Using fsolve() to solve non-linear system equation - 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: Using fsolve() to solve non-linear system equation ( /thread-13167.html) |

Using fsolve() to solve non-linear system equation - teerasak - 06-24-2019 08:00 AM
I have chance to use fsolve() to find numeric solution for single variable with the following options: - specify the initial guess, and the fsolve() will return a solution (that in fact, could be many) for example fsolve(x^2+2*x-3 = 0,x=0). This will give x=1 - specify the range of solution that we need fsolve() to search for - for example fsolve(x^2 + 2*x - 3=0, x=-10..10). This will give x = -3,1 However, with 2-variable system equation, I can find solution by fsolve() by providing only initial guess e.g fsolve({x^2 + y^2 =1, x+y=1}, {x=0,y=0}). this will give x= 6.09E-16 (which is close to 0), y= 1. But with 2-variable system equation, if I try to specify range of x, and y with the command below: fsolve({x^2 + y^2 =1, x+y=1}, {x=-10..10,y=-10..10}), it gives error!! Does anyone know how to let fsolve() to find solution for given range of x and y like the case above. Thank you very much. RE: Using fsolve() to solve non-linear system equation - parisse - 06-24-2019 05:53 PM
For univariate equations, a sign change on an interval warrants a root for a continuous fonction, it's not hard to implement a numeric solver on an interval. There is unfortunately no easy generalization for multivariate fonctions. That's why there is only an iterative implementation for generic systems, requiring a initial guess. However, polynomial systems like your system can be solved without initial guess with solve or fsolve (with [x,y] as 2nd argument). RE: Using fsolve() to solve non-linear system equation - teerasak - 06-24-2019 06:14 PM
Thank you, parisse. Got your point. Yes, in fact, this system equation can be solved by solve(). I would like to explore fsolve() as sometimes, solve() cannot provide find all solutions. For example, if I want to find the solution of the following system equation: x+y =5*Pi/4 tan(x)=1 Given x,y = 0..2*Pi solve({x+y=5*Pi/4, tan(x)=1},{x,y}) this gives [Pi/4, Pi]. However, there are some other solution too e.g [5*Pi/4, 0]. How can I find that another solution is [5*Pi/4, 0]? Because of this, I started finding out another command to search for more complete solution. RE: Using fsolve() to solve non-linear system equation - toml_12953 - 06-24-2019 11:48 PM
(06-24-2019 05:53 PM)parisse Wrote: For univariate equations, a sign change on an interval warrants a root for a continuous fonction, it's not hard to implement a numeric solver on an interval. There is unfortunately no easy generalization for multivariate fonctions. That's why there is only an iterative implementation for generic systems, requiring a initial guess. However, polynomial systems like your system can be solved without initial guess with solve or fsolve (with [x,y] as 2nd argument). Can a wrong initial guess eliminate the possibility of a solution? If not then why not let the machine make the guess internally? RE: Using fsolve() to solve non-linear system equation - Helge Gabert - 06-25-2019 01:50 AM
Good starting values are important, you just have to experiment a little. For example, fsolve([x+y=5/4*\pi, tan(x)=1],[x,y],[\pi,\pi]) returns [3.92699..., -1.01...e-15], which is your desired second solution, or [5*\pi/4,0]. RE: Using fsolve() to solve non-linear system equation - teerasak - 06-25-2019 04:19 AM
For fsolve(), yeah you are right. we need to try different initial guess. It works somehow. But it will be great if we can specify the range that fsolve() to find the solution which is available for one variable, but not multiple variables, as parisse said. For solve({x+y=5*Pi/4, tan(x)=1},{x,y}), I though solve() will give a complete solution, as it solved symbolically. RE: Using fsolve() to solve non-linear system equation - parisse - 06-25-2019 06:24 AM
Multivariate solve works for polynomial systems (or polynomial like). This is not the case for your system. Since your system is triangular, you can solve it by calling solve twice, first with second equation and variable x, then with 1st equation and variable y. RE: Using fsolve() to solve non-linear system equation - teerasak - 06-25-2019 07:26 AM
@parisse - got your point. Thank you. |