HP Forums
fsolve accuracy with complex variables [SOLVED] - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: fsolve accuracy with complex variables [SOLVED] (/thread-5650.html)



fsolve accuracy with complex variables [SOLVED] - JMB - 02-07-2016 11:25 AM

The following equation:
|x|^2-200*x+500+500*i = 0 (eq1)

where x is a complex variable, can be solved splitting it into two separate equations, one for the real part and another for the imaginary part. Applying this method, one gets the solution:
197.43587635+2.5*i (sol1)

Substituting sol1 into eq1, gives the exact value 0. Now, I was trying to solve this same equation using the function fsolve:

fsolve(|x|^2-200*x+500+500*i,x,190+i)

The calculator (firmware 8051) returns the value:
197.501663563-2.56405881565*i (sol2)

Trying different initials guesses leads to the same solution. The real parts of sol1 and sol2 are quite close, but not the imaginary parts.

Also: ABS(sol1)-ABS(sol2) = -0.066603127, and ARG(sol1)-ARG(sol2) = 2.56433999704E-2 (in radiants). So, depending on how you look at it, the solution given by fsolve is not so bad.

Does anyone know how to improve the calculator's accuracy?


RE: fsolve accuracy with complex variables - DrD - 02-07-2016 02:12 PM

Have you experimented with Epsilon on page 2 of the CAS settings? I don't know that it would help, but might improve convergence accuracy, albeit with a time cost.

-Dale-


RE: fsolve accuracy with complex variables - parisse - 02-07-2016 02:42 PM

Unfortunately the solver simplified abs(x)^2 to x^2 (fsolve is essentially a real solver), this will happen with non holomorphic functions like re/im/conj/abs.
You can set z:=x+i*y; Z:=abs(z)^2-200*z+500+500*i; then solve([re(Z),im(Z)],[x,y]) for exact and fsolve for approx solutions.


RE: fsolve accuracy with complex variables - JMB - 02-07-2016 03:28 PM

Thank you very much for your answers.

My Epsilon is set to 1e-12. Changing it to different values made no difference.

The solution provided by Parisse works just fine. After the definitions:

z:=x+i*y
eq:=|z|^2-200*z+500+500*i

Both solve and fsolve return the correct solution:

solve([re(eq),im(eq)],[x,y],[190,1]) -> [197.43587635 2.5]

fsolve([re(eq),im(eq)],[x,y],[190,1]) -> [197.43587635 2.5]