Using fsolve() to solve nonlinear system equation

06242019, 08:00 AM
Post: #1




Using fsolve() to solve nonlinear system equation
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*x3 = 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 2variable 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.09E16 (which is close to 0), y= 1. But with 2variable 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. 

06242019, 05:53 PM
(This post was last modified: 06242019 05:54 PM by parisse.)
Post: #2




RE: Using fsolve() to solve nonlinear system equation
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).


06242019, 06:14 PM
Post: #3




RE: Using fsolve() to solve nonlinear system equation
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. 

06242019, 11:48 PM
(This post was last modified: 06252019 10:38 AM by toml_12953.)
Post: #4




RE: Using fsolve() to solve nonlinear system equation
(06242019 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? Tom L French phrases you rarely hear: "trop de beurre" (too much butter) 

06252019, 01:50 AM
(This post was last modified: 06252019 01:52 AM by Helge Gabert.)
Post: #5




RE: Using fsolve() to solve nonlinear system equation
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...e15], which is your desired second solution, or [5*\pi/4,0]. 

06252019, 04:19 AM
Post: #6




RE: Using fsolve() to solve nonlinear system equation
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. 

06252019, 06:24 AM
Post: #7




RE: Using fsolve() to solve nonlinear system equation
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.


06252019, 07:26 AM
Post: #8




RE: Using fsolve() to solve nonlinear system equation
@parisse  got your point. Thank you.


« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)