MATLAB: The root finding using fsolve

non-linear equations

is there any way using fsolve to get 'all' possible solutions for equations? it just shows me the closest root to the initial guess!

Best Answer

There are essentially no tools that are absolutely assured to generate ALL solutions to a fully general nonlinear problem. Such global optimization problems (root finding is in that general family) can be made arbitrarily difficult.
In particular, fsolve is designed to return ONLY one solution. So it is working exactly as designed, and you cannot tell it to find multiple solutions.
On top of all this, one can easily generate problems with infinitely many solutions. For a trivial example, find all roots of the equation
sin(x) == 0.5
While you can write those solutions in a general form, that would not be a numerical solution then, so fsolve could not do so. And do you have enough memory to store infinitely many numerical solutions? The last time I checked, infinity was a big number. As well, it is as trivial to give an example where there is no easily written solution in general.
You can use the global optimization toolbox. Or you can use a multi-start method, so restart the optimizer from a variety of random places, then make sure you recognize that some of those solutions will be essential replicates to within slop.