- #1
okkvlt
- 53
- 0
First, Is there a way to convert a complex number to polar form without using boolean commands?
And now, my real question:
Do all of viete's formulas hold true when the coefficients of a cubic formula are complex?
I wrote a script that finds the roots of a cubic formula with complex coefficients. At the end of the script i added some lines that check the roots using viete's formulas. But either somethings wrong with the script, or one of viete's formulas isn't true for polynomials with complex coefficients. I am guessing there's something wrong with the script.
x1+x2+x3 always equals -b/a, as it should
x1*x2+x1*x3+x2*x3 always equals c/a, as it should
but x1*x2*x3 does not equal -d/a, and i can't figure out why.
I looked over the script many times, and i can't find anything wrong with it. I'm sure the problem must be with the way i checked the roots, because the roots have to be correct for two of the formulae to work all the time. But i looked over the checking part of the script line by line and couldn't find anything wrong. The problem is that the values rproduct and rvieteproduct, and iproduct and ivieteproduct are not equal.
Maybe there's a real part of a complex number somewhere in the calculations that always equals zero and that screws up my polar form conversion. The problem with the program I am using is i can't use the equal sign in boolean conditions, only < and >. Can anybody think of a way to get around this?
Here's the script. It's fairly well organized. something like lzl is the magnitude of z, argz is the argument of z, rez or rz is the real part of z, imz or iz is the imaginary part of z. The coefficients are denoted by the letter of the coefficient(a,b,c,d) followed by r or i.
If you have the program "GraphCalc",(its freeware) you can run the script yourself to see what i mean.
#The Cubic Formula with complex coefficients
[Tab=output]
[PromptVal=ar:enter the real part of the coefficient of x^3]
[PromptVal=ai:enter the imaginary part of the coefficient of x^3]
[PromptVal=br:enter the real part of the coefficient of x^2]
[PromptVal=bi:enter the imaginary part of the coefficient of x^2]
[PromptVal=cr:enter the real part of the coefficient of x^1]
[PromptVal=ci:enter the imaginary part of the coefficient of x^1]
[PromptVal=dr:enter the real part of the coefficient of x^0]
[PromptVal=di:enter the imaginary part of the coefficient of x^0]
lal=(ar^2+ai^2)^.5
If(ar > 0)
arga=arctan(ai/ar)
EndIf
If(ar < 0)
arga=arctan(ai/ar)+pi
EndIf
lbl=(br^2+bi^2)^.5
If(br > 0)
argb=arctan(bi/br)
EndIf
If(br < 0)
argb=arctan(bi/br)+pi
EndIf
lcl=(cr^2+ci^2)^.5
If(cr > 0)
argc=arctan(ci/cr)
EndIf
If(cr < 0)
argc=arctan(ci/cr)+pi
EndIf
ldl=(dr^2+di^2)^.5
If(dr > 0)
argd=arctan(di/dr)
EndIf
If(dr < 0)
argd=arctan(di/dr)+pi
EndIf
ref=(lcl/lal)*cos(argc-arga)-(lbl^2/(3*lal^2))*cos(2*argb-2*arga)
imf=(lcl/lal)*sin(argc-arga)-(lbl^2/(3*lal^2))*sin(2*argb-2*arga)
reg=(2*lbl^3/(27*lal^3))*cos(3*argb-3*arga)+(ldl/lal)*cos(argd-arga)-((lcl*lbl)/(3*lal^2))*cos(argc+argb-2*arga)
img=(2*lbl^3/(27*lal^3))*sin(3*argb-3*arga)+(ldl/lal)*sin(argd-arga)-((lcl*lbl)/(3*lal^2))*sin(argc+argb-2*arga)
rep=lbl/(3*lal)*cos(argb-arga)
imp=lbl/(3*lal)*sin(argb-arga)
If(reg > 0)
argg=arctan(img/reg)
EndIf
If(reg < 0)
argg=arctan(img/reg)+pi
EndIf
lgl=(reg^2+img^2)^.5
If(ref > 0)
argf=arctan(imf/ref)
EndIf
If(ref < 0)
argf=arctan(imf/ref)+pi
EndIf
lfl=(ref^2+imf^2)^.5
req=27*lgl^2*cos(2*argg)+4lfl^3*cos(3*argf)
imq=27*lgl^2*sin(2*argg)+4lfl^3*sin(3*argf)
lql=(req^2+imq^2)^.5
If(req > 0)
argq=arctan(imq/req)
EndIf
If(req < 0)
argq=arctan(imq/req)+pi
EndIf
resquareroot=lql^.5*cos(argq/2)
imsquareroot=lql^.5*sin(argq/2)
reinside=reg/(-27^.5)+resquareroot
iminside=img/(-27^.5)+imsquareroot
linsidel=(reinside^2+iminside^2)^.5
If(reinside > 0)
arginside=arctan(iminside/reinside)
EndIf
If(reinside < 0)
arginside=arctan(iminside/reinside)+pi
EndIf
recuberoot1=linsidel^(1/3)*cos(arginside/3)
imcuberoot1=linsidel^(1/3)*sin(arginside/3)
lcuberootl=(recuberoot1^2+imcuberoot1^2)^.5
If(recuberoot1 > 0)
argcuberoot1=arctan(imcuberoot1/recuberoot1)
argcuberoot2=argcuberoot1+(2pi)/3
argcuberoot3=argcuberoot1+(4pi)/3
EndIf
If(recuberoot1 < 0)
argcuberoot1=arctan(imcuberoot/recuberoot)+pi
argcuberoot2=argcuberoot1-(2pi)/3+pi
argcuberoot3=argcuberoot1-(4pi)/3+pi
EndIf
recuberoot1=lcuberootl*cos(argcuberoot1)
imcuberoot1=lcuberootl*sin(argcuberoot1)
recuberoot2=lcuberootl*cos(argcuberoot2)
imcuberoot2=lcuberootl*sin(argcuberoot2)
recuberoot3=lcuberootl*cos(argcuberoot3)
imcuberoot3=lcuberootl*sin(argcuberoot3)
releft1=recuberoot1/2^(1/3)
imleft1=imcuberoot1/2^(1/3)
releft2=recuberoot2/2^(1/3)
imleft2=imcuberoot2/2^(1/3)
releft3=recuberoot3/2^(1/3)
imleft3=imcuberoot3/2^(1/3)
ltoprightl=lfl*2^(1/3)
reright1=(ltoprightl/lcuberootl)*cos(argf-argcuberoot1)
imright1=(ltoprightl/lcuberootl)*sin(argf-argcuberoot1)
reright2=(ltoprightl/lcuberootl)*cos(argf-argcuberoot2)
imright2=(ltoprightl/lcuberootl)*sin(argf-argcuberoot2)
reright3=(ltoprightl/lcuberootl)*cos(argf-argcuberoot3)
imright3=(ltoprightl/lcuberootl)*sin(argf-argcuberoot3)
[Comment=" "]
[Comment="-"]
[Comment="--"]
[Comment="---"]
[Comment="----"]
[Comment="-----"]
[Comment="x equals"]
rx1=(releft1-reright1)/3^.5-rep
ix1=(imleft1-imright1)/3^.5-imp
[Comment=" "]
[Comment="-"]
[Comment="--"]
[Comment="---"]
[Comment="----"]
[Comment="-----"]
[Comment="x equals"]
rx2=(releft2-reright2)/3^.5-rep
ix2=(imleft2-imright2)/3^.5-imp
[Comment=" "]
[Comment="-"]
[Comment="--"]
[Comment="---"]
[Comment="----"]
[Comment="-----"]
[Comment="x equals"]
rx3=(releft3-reright3)/3^.5-rep
ix3=(imleft3-imright3)/3^.5-imp
[Comment=" "]
[Comment="-"]
[Comment="--"]
[Comment="---"]
[Comment="----"]
[Comment="-----"]
[Comment="checking answers"]
rsum=rx1+rx2+rx3
isum=ix1+ix2+ix3
rvietesum=lbl/lal*cos(argb-arga+pi)
ivietesum=lbl/lal*sin(arga-argb+pi)
lx1l=(rx1^2+ix1^2)^.5
If(rx1 > 0)
argx1=arctan(ix1/rx1)
EndIf
If(rx1 < 0)
argx1=arctan(ix1/rx1)+pi
EndIf
lx2l=(rx2^2+ix2^2)^.5
If(rx2 > 0)
argx2=arctan(ix2/rx2)
EndIf
If(rx2 < 0)
argx2=arctan(ix2/rx2)+pi
EndIf
lx3l=(rx3^2+ix3^2)^.5
If(rx3 > 0)
argx3=arctan(ix3/rx3)
EndIf
If(rx3 < 0)
argx3=arctan(ix3/rx3)+pi
EndIf
rproductsum=lx1l*lx2l*cos(argx1+argx2)+lx1l*lx3l*cos(argx1+argx3)+lx2l*lx3l*cos(argx2+argx3)
iproductsum=lx1l*lx2l*sin(argx1+argx2)+lx1l*lx3l*sin(argx1+argx3)+lx2l*lx3l*sin(argx2+argx3)
rvieteproductsum=lcl/lal*cos(argc-arga)
ivieteproductsum=lcl/lal*sin(argc-arga)
rproduct=(lx1l*lx2l*lx3l)*cos(argx1+argx2+argx3)
iproduct=(lx1l*lx2l*lx3l)*sin(argx1+argx2+argx3)
rvieteproduct=(ldl/lal)*cos(argd-arga+pi)
ivieteproduct=(ldl/lal)*sin(argd-arga+pi)
[Comment="The following pairs of terms should be equal"]
[Comment="-----"]
rsum
rvietesum
[Comment="-----"]
isum
ivietesum
[Comment="-----"]
rproduct
rvieteproduct
[Comment="-----"]
iproduct
ivieteproduct
[Comment="-----"]
rproductsum
rvieteproductsum
[Comment="-----"]
iproductsum
ivieteproductsum
And now, my real question:
Do all of viete's formulas hold true when the coefficients of a cubic formula are complex?
I wrote a script that finds the roots of a cubic formula with complex coefficients. At the end of the script i added some lines that check the roots using viete's formulas. But either somethings wrong with the script, or one of viete's formulas isn't true for polynomials with complex coefficients. I am guessing there's something wrong with the script.
x1+x2+x3 always equals -b/a, as it should
x1*x2+x1*x3+x2*x3 always equals c/a, as it should
but x1*x2*x3 does not equal -d/a, and i can't figure out why.
I looked over the script many times, and i can't find anything wrong with it. I'm sure the problem must be with the way i checked the roots, because the roots have to be correct for two of the formulae to work all the time. But i looked over the checking part of the script line by line and couldn't find anything wrong. The problem is that the values rproduct and rvieteproduct, and iproduct and ivieteproduct are not equal.
Maybe there's a real part of a complex number somewhere in the calculations that always equals zero and that screws up my polar form conversion. The problem with the program I am using is i can't use the equal sign in boolean conditions, only < and >. Can anybody think of a way to get around this?
Here's the script. It's fairly well organized. something like lzl is the magnitude of z, argz is the argument of z, rez or rz is the real part of z, imz or iz is the imaginary part of z. The coefficients are denoted by the letter of the coefficient(a,b,c,d) followed by r or i.
If you have the program "GraphCalc",(its freeware) you can run the script yourself to see what i mean.
#The Cubic Formula with complex coefficients
[Tab=output]
[PromptVal=ar:enter the real part of the coefficient of x^3]
[PromptVal=ai:enter the imaginary part of the coefficient of x^3]
[PromptVal=br:enter the real part of the coefficient of x^2]
[PromptVal=bi:enter the imaginary part of the coefficient of x^2]
[PromptVal=cr:enter the real part of the coefficient of x^1]
[PromptVal=ci:enter the imaginary part of the coefficient of x^1]
[PromptVal=dr:enter the real part of the coefficient of x^0]
[PromptVal=di:enter the imaginary part of the coefficient of x^0]
lal=(ar^2+ai^2)^.5
If(ar > 0)
arga=arctan(ai/ar)
EndIf
If(ar < 0)
arga=arctan(ai/ar)+pi
EndIf
lbl=(br^2+bi^2)^.5
If(br > 0)
argb=arctan(bi/br)
EndIf
If(br < 0)
argb=arctan(bi/br)+pi
EndIf
lcl=(cr^2+ci^2)^.5
If(cr > 0)
argc=arctan(ci/cr)
EndIf
If(cr < 0)
argc=arctan(ci/cr)+pi
EndIf
ldl=(dr^2+di^2)^.5
If(dr > 0)
argd=arctan(di/dr)
EndIf
If(dr < 0)
argd=arctan(di/dr)+pi
EndIf
ref=(lcl/lal)*cos(argc-arga)-(lbl^2/(3*lal^2))*cos(2*argb-2*arga)
imf=(lcl/lal)*sin(argc-arga)-(lbl^2/(3*lal^2))*sin(2*argb-2*arga)
reg=(2*lbl^3/(27*lal^3))*cos(3*argb-3*arga)+(ldl/lal)*cos(argd-arga)-((lcl*lbl)/(3*lal^2))*cos(argc+argb-2*arga)
img=(2*lbl^3/(27*lal^3))*sin(3*argb-3*arga)+(ldl/lal)*sin(argd-arga)-((lcl*lbl)/(3*lal^2))*sin(argc+argb-2*arga)
rep=lbl/(3*lal)*cos(argb-arga)
imp=lbl/(3*lal)*sin(argb-arga)
If(reg > 0)
argg=arctan(img/reg)
EndIf
If(reg < 0)
argg=arctan(img/reg)+pi
EndIf
lgl=(reg^2+img^2)^.5
If(ref > 0)
argf=arctan(imf/ref)
EndIf
If(ref < 0)
argf=arctan(imf/ref)+pi
EndIf
lfl=(ref^2+imf^2)^.5
req=27*lgl^2*cos(2*argg)+4lfl^3*cos(3*argf)
imq=27*lgl^2*sin(2*argg)+4lfl^3*sin(3*argf)
lql=(req^2+imq^2)^.5
If(req > 0)
argq=arctan(imq/req)
EndIf
If(req < 0)
argq=arctan(imq/req)+pi
EndIf
resquareroot=lql^.5*cos(argq/2)
imsquareroot=lql^.5*sin(argq/2)
reinside=reg/(-27^.5)+resquareroot
iminside=img/(-27^.5)+imsquareroot
linsidel=(reinside^2+iminside^2)^.5
If(reinside > 0)
arginside=arctan(iminside/reinside)
EndIf
If(reinside < 0)
arginside=arctan(iminside/reinside)+pi
EndIf
recuberoot1=linsidel^(1/3)*cos(arginside/3)
imcuberoot1=linsidel^(1/3)*sin(arginside/3)
lcuberootl=(recuberoot1^2+imcuberoot1^2)^.5
If(recuberoot1 > 0)
argcuberoot1=arctan(imcuberoot1/recuberoot1)
argcuberoot2=argcuberoot1+(2pi)/3
argcuberoot3=argcuberoot1+(4pi)/3
EndIf
If(recuberoot1 < 0)
argcuberoot1=arctan(imcuberoot/recuberoot)+pi
argcuberoot2=argcuberoot1-(2pi)/3+pi
argcuberoot3=argcuberoot1-(4pi)/3+pi
EndIf
recuberoot1=lcuberootl*cos(argcuberoot1)
imcuberoot1=lcuberootl*sin(argcuberoot1)
recuberoot2=lcuberootl*cos(argcuberoot2)
imcuberoot2=lcuberootl*sin(argcuberoot2)
recuberoot3=lcuberootl*cos(argcuberoot3)
imcuberoot3=lcuberootl*sin(argcuberoot3)
releft1=recuberoot1/2^(1/3)
imleft1=imcuberoot1/2^(1/3)
releft2=recuberoot2/2^(1/3)
imleft2=imcuberoot2/2^(1/3)
releft3=recuberoot3/2^(1/3)
imleft3=imcuberoot3/2^(1/3)
ltoprightl=lfl*2^(1/3)
reright1=(ltoprightl/lcuberootl)*cos(argf-argcuberoot1)
imright1=(ltoprightl/lcuberootl)*sin(argf-argcuberoot1)
reright2=(ltoprightl/lcuberootl)*cos(argf-argcuberoot2)
imright2=(ltoprightl/lcuberootl)*sin(argf-argcuberoot2)
reright3=(ltoprightl/lcuberootl)*cos(argf-argcuberoot3)
imright3=(ltoprightl/lcuberootl)*sin(argf-argcuberoot3)
[Comment=" "]
[Comment="-"]
[Comment="--"]
[Comment="---"]
[Comment="----"]
[Comment="-----"]
[Comment="x equals"]
rx1=(releft1-reright1)/3^.5-rep
ix1=(imleft1-imright1)/3^.5-imp
[Comment=" "]
[Comment="-"]
[Comment="--"]
[Comment="---"]
[Comment="----"]
[Comment="-----"]
[Comment="x equals"]
rx2=(releft2-reright2)/3^.5-rep
ix2=(imleft2-imright2)/3^.5-imp
[Comment=" "]
[Comment="-"]
[Comment="--"]
[Comment="---"]
[Comment="----"]
[Comment="-----"]
[Comment="x equals"]
rx3=(releft3-reright3)/3^.5-rep
ix3=(imleft3-imright3)/3^.5-imp
[Comment=" "]
[Comment="-"]
[Comment="--"]
[Comment="---"]
[Comment="----"]
[Comment="-----"]
[Comment="checking answers"]
rsum=rx1+rx2+rx3
isum=ix1+ix2+ix3
rvietesum=lbl/lal*cos(argb-arga+pi)
ivietesum=lbl/lal*sin(arga-argb+pi)
lx1l=(rx1^2+ix1^2)^.5
If(rx1 > 0)
argx1=arctan(ix1/rx1)
EndIf
If(rx1 < 0)
argx1=arctan(ix1/rx1)+pi
EndIf
lx2l=(rx2^2+ix2^2)^.5
If(rx2 > 0)
argx2=arctan(ix2/rx2)
EndIf
If(rx2 < 0)
argx2=arctan(ix2/rx2)+pi
EndIf
lx3l=(rx3^2+ix3^2)^.5
If(rx3 > 0)
argx3=arctan(ix3/rx3)
EndIf
If(rx3 < 0)
argx3=arctan(ix3/rx3)+pi
EndIf
rproductsum=lx1l*lx2l*cos(argx1+argx2)+lx1l*lx3l*cos(argx1+argx3)+lx2l*lx3l*cos(argx2+argx3)
iproductsum=lx1l*lx2l*sin(argx1+argx2)+lx1l*lx3l*sin(argx1+argx3)+lx2l*lx3l*sin(argx2+argx3)
rvieteproductsum=lcl/lal*cos(argc-arga)
ivieteproductsum=lcl/lal*sin(argc-arga)
rproduct=(lx1l*lx2l*lx3l)*cos(argx1+argx2+argx3)
iproduct=(lx1l*lx2l*lx3l)*sin(argx1+argx2+argx3)
rvieteproduct=(ldl/lal)*cos(argd-arga+pi)
ivieteproduct=(ldl/lal)*sin(argd-arga+pi)
[Comment="The following pairs of terms should be equal"]
[Comment="-----"]
rsum
rvietesum
[Comment="-----"]
isum
ivietesum
[Comment="-----"]
rproduct
rvieteproduct
[Comment="-----"]
iproduct
ivieteproduct
[Comment="-----"]
rproductsum
rvieteproductsum
[Comment="-----"]
iproductsum
ivieteproductsum