I have a little bit of a problem trying to find solutions to (a1+a2*i)^(b1+b2*i). A big problem is that... there are an infinite number of solutions (in most cases). Using euler's equation, I found this:
[code brackets to prevent smilies
(a1+a2*i)^(b1+b2*i)=(|a|*e^(i*arg(a)))*(b1+b2*i) (where arg(a) is the complex argument of a, and |a| is the "length" of a.)
...
=e^(b1*ln(|a|)-b2*arg(a))*(cos(arg(a)*b1+b2*ln(|a|))+i*sin(arg(a)*b1+b2*ln(|a|)))
The problem of infinite solutions arises because arg(a) and ln(|a|) can be incremented by any integer multiple of 2*pi without changing |a|*e^(i*arg(a)).
So... that's (kind of) all well and good. But... when I try to implement it.. stuff doesn't work right.
here's my code (there are... four or so lines that use cloggy's DLL, but just replace those with dot or circle and it'll run fine. Also ianm's matrixutil's log function).
Rem Project: Dark Basic Pro Project
Rem Created: Wednesday, June 09, 2010
Rem ***** Main Source File *****
Rem Created: Wednesday, June 09, 2010
Rem ***** Main Source File *****
d3d_init
dim ret(-1) as dword
global retx as float
global rety as float
global pixels_per_unit as float
pixels_per_unit=100.0
global imag1 as dword
global imag2 as dword
imag1=zCreate(2,0)
imag2=zCreate(2,0)
sync on
do
cls
if mouseclick()
toUnits(mousex(),mousey())
if keystate(30) then rety=0
if keystate(31) then retx=0
if spacekey()
zSet(imag2,retx,rety)
else
zSet(imag1,retx,rety)
endif
endif
clearRet()
zDraw(imag1,rgb(255,255,255))
zDraw(imag2,rgb(255,255,255))
zPower(imag1,imag2,10,10)
drawGraphPaper(pixels_per_unit, screen width()/2,screen height()/2,1)
for n=0 to array count(ret())
`just ta get a nice, consistent color:
value as dword
value=(2^24)*n*1.0/(array count(ret()))
r as dword
g as dword
b as dword
r=(value and %111111110000000000000000)>>16
g=(value and %000000001111111100000000)>>8
b=(value and %000000000000000011111111)>>0
r=minimum(r+40,255)
g=minimum(g+40,255)
b=minimum(b+40,255)
zDraw(ret(n),rgb(r,g,b))
next
text 0,16,zString(imag1)+"^("+zString(imag2)+")"
tempx as integer
tempy as integer
for n=0 to array count(ret())
//text tempx,tempy,zString(ret(n))
//tempy=tempy+16
//if tempy>screen height()
// tempy=0
// tempx=tempx+55
//endif
next
sync
loop
function minimum(a as dword, b as dword)
if a>b then exitfunction b
endfunction a
function zString(a as dword)
s$=str$(peek float(a))+" + i*"+str$(peek float(a+4))
endfunction s$
function zCreate(a as float, b as float)
mem as dword
mem=alloc(12)
poke dword mem+8,1
poke float mem+0,a
poke float mem+4,b
endfunction mem
function zDestroy(a as dword)
free a
endfunction
function zDraw(a as dword,color as dword)
toScreen(peek float(a),peek float(a+4))
d3d_circle retx,rety,4,1,color
endfunction
function zDivide(result as dword, a as dword, b as dword)
div#=peek float(b)*peek float(b)+peek float(b+4)*peek float(b+4)
poke float result, (peek float(a)*peek float(b)+peek float(a+4)*peek float(b+4))/div#
poke float result+4,(peek float(a+4)*peek float(b)+peek float(a)*peek float(b+4))/div#
endfunction
function zAdd(result as dword, a as dword, b as dword)
poke float result,peek float(a)+peek float(b)
poke float result+4,peek float(a+4)+peek float(b+4)
endfunction
function zSubtract(result as dword, a as dword, b as dword)
poke float result,peek float(a)-peek float(b)
poke float result+4,peek float(a+4)-peek float(b+4)
endfunction
function zMultiply(result as dword, a as dword, b as dword)
poke float result,peek float(a)*peek float(b)-peek float(a+4)-peek float(b+4)
poke float result+4,peek float(a+4)*peek float(b)+peek float(a)*peek float(b+4)
endfunction
function zParse(s as string)
a as string
b as string
lr as boolean
for n=1 to len(s)
temp$=mid$(s,n)
if asc(temp$)>=asc("0") and asc(temp$)<=asc("9")
endif
next
endfunction
function zArg(a as dword) //in degrees
ang#=atanfull(peek float(a),peek float(a+4))
endfunction ang#
function zAbs(a as dword)
ret#=sqrt(peek float(a)*peek float(a)+peek float(a+4)*peek float(a+4))
endfunction ret#
function zSet(mem as dword, a as float, b as float)
poke float mem,a
poke float mem+4,b
endfunction
function zPower(a as dword,b as dword,num as dword,num2 as dword) `(a1+a2*i)^(b1+b2*i)
`fills ret() with values taking zArg from -num*2*pi*i to num*2*pi*i
n as integer
pzArg_degA as float
newzArg as float
lnAbsA as float
pzArg_degA=zArg(a) `principal complex argument of a in degrees
`e^(b1*ln(|a|)-b2*arg(a)) * e^(i*(arg(a)*b1+b2*ln(|a|)))
`theta=arg(a)*b1+b2*ln(|a|)
`(a1+a2*i)^(b1+b2*i)=e^(b1*ln(|a|)-b2*arg(a)) * (cos(theta)+i*sin(theta))
`-------------------------------------^^^^ responsible for the infinite number of solutions :\
text 0,0,str$( pzArg_degA)
for n2=-num2 to num2
lnAbsA=log(zAbs(a))+6.28318531*n2 `ln(|a|) Yes ln(n) has an infinite number of solutions. BLARGH.
for n=-num to num
array insert at bottom ret()
ret(array count(ret()))=zCreate(0,0)
newzArg=pzArg_degA+360*n
theta#=newzArg*peek float(b)+peek float(b+4)*lnAbsA*57.29577951 `~=(newzArg*pi/180*b1+b2*ln(|a|))*180/pi=newzArg*b1+b2*ln(|a|)*180/pi
magnitude#=2.71828183^(peek float(b)*lnAbsA-peek float(b+4)*newzArg*.017453293) `peek float(b)*lnAbsA-b2*arg(a) where arg(a) is in radians.
`now (a1+a2i)^(b1+b2i)=magnitude#*(cos(theta#)+isin(theta#))
``print n
`print newzArg
`print lnAbsA
`print newzArg
`print magnitude#
`sync
`wait key
poke float ret(array count(ret())),magnitude#*cos(theta#+90)
poke float ret(array count(ret()))+4,magnitude#*sin(theta#+90)
next
next
endfunction
function clearRet()
c as integer
c=array count(ret())
for n=0 to c
zDestroy(ret(n))
next
empty array ret()
endfunction
function drawGraphPaper(PPU as integer, midx as integer, midy as integer, subUnits as integer)
if subunits<=0 then subunits=1
if PPU<=0 then ppu=40
subDist as float
subDist=PPU*1.0/subUnits
counter1 as float =
counter1=-PPU
counter2 as float = 0
w=screen width()
h=screen height()
ink rgb(0,0,40)
line 0,h/2,w,h/2
ink rgb(0,40,0)
line w/2,0,w/2,h
while (counter1+midx<w) or (midx-counter1>0)
inc counter1, PPU
counter2=0
while (counter2<PPU)
inc counter2, subDist
ink rgb(150,150,150),0
line midx+counter1+counter2,midy-2,midx+counter1+counter2,midy+2
line midx-counter1+counter2,midy-2,midx-counter1+counter2,midy+2
endwhile
ink rgb(255,255,255),0
line midx+counter1,midy-5,midx+counter1,midy+5
line midx-counter1,midy-5,midx-counter1,midy+5
endwhile
counter1=-PPU
counter2=0
while (counter1+midy<w) or (midy-counter1>0)
inc counter1, PPU
counter2=0
while (counter2<PPU)
inc counter2, subDist
ink rgb(150,150,150),0
line midx-2,midy+counter1+counter2,midx+2,midy+counter1+counter2
line midx-2,midy-counter1-counter2,midx+2,midy-counter1-counter2
endwhile
ink rgb(255,255,255),0
line midx-4,midy+counter1,midx+4,midy+counter1
line midx-4,midy-counter1,midx+4,midy-counter1
endwhile
endfunction
function toUnits(x as float, y as float)
retx=(x-screen width()/2)/pixels_per_unit
rety=(y-screen height()/2)/pixels_per_unit
endfunction
function toScreen(x as float, y as float)
retx=x*pixels_per_unit+screen width()/2
rety=-y*pixels_per_unit+screen height()/2
endfunction
It gives weird results... but it doesn't appear to be completely wrong... just off by some angle or something. For example, (0+1*i)^(0.5+0*i), or sqrt(i) returns the two values 1*i or -1*i. This is incorrect, but sqrt(1+0*i)^(0.5+0*i), the square root of negative one, is one or negative one. This isn't just a single special case coincidence. Another example:
(1+0*i)^(0.5+0*i) gives 0.70710+0.70710*i and -0.70710-0.70710*i. Obviously incorrect, but true for (0+1*i)^(0.5+0*i).
I don't get what's going on. Any help? i would just swap a1 and a2 but... i have no reason to do so (also it's 1:00 and I have stuff to do tomorrow

)

Is't life, I ask, is't even prudence, to bore thyself and bore thy students?