# fsolve stopped because the problem appears regular

120 views (last 30 days)
Bodhisatwa Goswami on 28 Oct 2017
Edited: John D'Errico on 28 Oct 2017
Hi,
I am trying to solve a simple problem but somehow stuck with the output:
fsolve stopped because the problem appears regular as measured by the gradient, but the vector of function values is not near zero as measured by the default value of the function tolerance.
Would appreciate some help!
function F = root2d(x)
F(1) = (39*x(1)^2*x(2)^2)/100 - (x(2)^2)/5 - 2*x(1)^2 + 1;
F(2) = (39*x(1)^2*x(2)^2)/100 - (7*x(2)^2)/25 - (14*x(1)^2)/5 + 49/25
And my script says
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)

John D'Errico on 28 Oct 2017
Edited: John D'Errico on 28 Oct 2017
It is NEVER a good idea to start any optimization at zero. That may easily screw up the gradient estimation, in case the code uses a relative increment on the variables. A random starting point, when you don't have a good idea of a guess, is always safer. Best of course is to use a start point that is close to the result.
No need to use an m-file function here. A function handle is sufficient.
F = @(x) [(39*x(1)^2*x(2)^2)/100 - (x(2)^2)/5 - 2*x(1)^2 + 1;(39*x(1)^2*x(2)^2)/100 - (7*x(2)^2)/25 - (14*x(1)^2)/5 + 49/25];
[x,fval] = fsolve(F,rand(1,2))
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
x =
0.795 2.3832
fval =
-8.908e-07
-1.0553e-06

#### 1 Comment

Bodhisatwa Goswami on 28 Oct 2017
Thanks a lot for the prompt reply! That worked! Also thanks for the suggestions!

Walter Roberson on 28 Oct 2017
Use any starting point whose components have absolute value 1E-7 or higher (approximately).
There are 8 solutions to those equations and your starting point [0 0] is in the middle of all of them; the algorithm cannot figure out which direction to head (the algorithm does not make random choices.) Using a non-zero starting point places one of the solutions closer and allows it to be found.