The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

HP Prime Solving Nonlinear System of Equations for Complex Results
Message #1 Posted by Helge Gabert on 29 Sept 2013, 12:51 p.m.

Apparently, the built-in App (Solve) doesn't allow complex starting values, and doesn't search for complex solutions - - or does it?

I tried to use csolve(), but that only allows a single equation to be entered, and also fsolve(), but the syntax is not clear to me. The help screen states, that a numerical solution of a system of equations can be returned, but the syntax given is fsolve(Expr, Var, [Guess or interval], [Method]). I'm not sure how to use this with more than one non-linear equation.

By the way, how many methods are there to choose from? Not clear from the user's guide).

I'm really looking for something like Sune Bredahl's excellent Solvesys for the HP49G+ and HP50G (couldn't something along those lines have been implemented for the Prime?), or even like the somewhat clunkier and slower MSLV (both return complex solutions).

For the built in solver (numeric view), some diagnostic output would be helpful as well (convergence, # iterations, etc.), along with an indication that the solver is running (so that he user isn't staring at a static screen, wondering if the Solve softkey has been tapped successfully).

      
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #2 Posted by Clayton Workman on 29 Sept 2013, 1:26 p.m.,
in response to message #1 by Helge Gabert

You can get complex results by using the reduced row echelon method of solving a linear system.

For example, suppose you have the following two equations:

(5+6i)x + (3+8i)y = 9

(2+4i)x + (-3+5i)y = 4.5+6i

You would create a matrix (i.e., M1) as follows:

5+6i 3+8i 9

2+4i -3+5i 4.5+6i

Now use the command RREF(M1) and you will get the following resulting matrix (I'm rounding the values for simplicity):

1 0 0.058+0.410i

0 1 0.196-1.322i

which means x=0.058+0.410i and y=0.196-1.322i.

Using this method, you can solve a linear system with pretty much any number of equations (well except for the limitations that the prime has on matrix sizes.)

Hope this helps.

-Clayton

            
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #3 Posted by Helge Gabert on 29 Sept 2013, 1:51 p.m.,
in response to message #2 by Clayton Workman

Yes this works for a linear, complex system - - thanks for the tip with RREF!

However, if the complex system is non-linear in the parameters . . .

                  
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #4 Posted by Clayton Workman on 29 Sept 2013, 1:53 p.m.,
in response to message #3 by Helge Gabert

Oops... I misread the title of your post as "linear" instead of "nonlinear". My apologies.

-Clayton

                        
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #5 Posted by Clayton Workman on 29 Sept 2013, 2:04 p.m.,
in response to message #4 by Clayton Workman

It looks like fsolve should do it, but even the example in the help section for fsolve causes an error in both home and CAS mode.

-Clayton

                              
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #6 Posted by Helge Gabert on 29 Sept 2013, 2:35 p.m.,
in response to message #5 by Clayton Workman

The example given for fsolve, i.e., fsolve(COS(x)=x,x)

works for me in CAS mode, returns .739...

Not in home mode, though, fsolve(COS(X)=X,X) returns "undef"

                                    
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #7 Posted by From Hong Kong on 29 Sept 2013, 2:49 p.m.,
in response to message #6 by Helge Gabert

In HOME mode, use FNROOT instead of fsolve:

FNROOT(COS(X)=X,X)

                                          
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #8 Posted by Helge Gabert on 29 Sept 2013, 3:01 p.m.,
in response to message #7 by From Hong Kong

Yes, that works! - - but not for systems of equations.

Thanks - - so for this problem (one variable nonlinear equation) use FNROOT in Home, and csolve in CAS!

      
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #9 Posted by From Hong Kong on 29 Sept 2013, 2:31 p.m.,
in response to message #1 by Helge Gabert

Use the cZeros function in CAS mode. Suppose there is a system of non-linear equations as follows:

x^2+y^2=1
y=-x-3

The input form is cZeros({x^2+y^2=1,y=-x-3},{x,y}). You'll get the result you want.

Edited: 29 Sept 2013, 2:33 p.m.

            
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #10 Posted by Helge Gabert on 29 Sept 2013, 2:40 p.m.,
in response to message #9 by From Hong Kong

YES! Thanks so much!

                  
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #11 Posted by Helge Gabert on 29 Sept 2013, 3:42 p.m.,
in response to message #10 by Helge Gabert

. . . with the caveat, that cZeros seems to be only working for polynomials, and not for general non-linear equations. try it and you will get an error, e.g., [x, x^y, sin (x*y)] is not rational w.r.t.

                        
Re: HP Prime Solving Nonlinear System of Equations for Complex Results
Message #12 Posted by From Hong Kong on 30 Sept 2013, 3:44 a.m.,
in response to message #11 by Helge Gabert

It isn't supported for the moment.

Edited: 30 Sept 2013, 3:45 a.m.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall