Guess for fsolve returns similar answer (heavily non-linear equations)

12 views (last 30 days)
I have a huge function (36 variables) that I am solving using fsolve and the optimization options as shown in the code below:
fun=@BIGFunc
x0[1:33]=[ones]
x0[34:36]=[5, 5, 5]
options = optimoptions('fsolve','Algorithm','levenberg-marquardt',...
'Display','iter','FunctionTolerance',1e-15,'TolX',1e-15,'MaxFunctionEvaluations', 12000,'MaxIterations',600);
[x,fval,EXITFLAG,OUTPUT] = fsolve(fun,x0,options)
The guesses for the first 33 variables are variant (I put them 1s as of simplicity. When solving the function, the answers for the 34-36 variables are just below the provided guess. For example, with a guess of 5, I get 4.9, and for 7, I get 6.9, and so on. Is there something wrong here or is my function extremely non-linear, which exihbits multiple solutions and is very subjective to my initial guess?
I would appreciate your inputs.
  7 Comments
John D'Errico
John D'Errico on 24 Jan 2021
Setting the toleracnce really small for fsolve is almost NEVER a good idea. It does not help. If no solution was found, it means there are likely numerical problems, or the starting values were poor, or that no solution really exists.
Omar Khalifa
Omar Khalifa on 24 Jan 2021
Ture that. Then I will try different initial guesses. I tried 10, but it took more than 2.5 hrs and didn't converge. I will also revisit the BIGfunc and look for numerical errors...

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 24 Jan 2021
We don't see your equations. Almost certainly, they are pretty nasty looking.
You tell us the exit flag was -2. That flag says fsolve has converged to a point that is not a root. So it cannot move, yet there is no solution at that point. Consider the polynomial...
p = @(x) -x.^3 + 9*x.^2 - 11*x + 24;
fplot(p,[-5,10])
yline(0);
In fact, we can see hat P likely has only one real root, if you understand that p is a cubic polynomial.
roots([-1 9 -11 24])
ans =
8.00000000000001 + 0i
0.5 + 1.6583123951777i
0.5 - 1.6583123951777i
There is a root at 8, and then a complex conjugate pair.
But, suppose we try using fsolve to find a root, and we are not careful to provide an intelligent starting value?
>> [xroot,fval,exitflag] = fsolve(p,0)
No solution found.
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
value of the function tolerance.
<stopping criteria details>
xroot =
0.690598919987679
fval =
20.366388514576
exitflag =
-2
As you can see, by starting fsolve in an area where while it can try to go downhill towards zero, it ALWAYS will fail! As long as the starting value is roughly below 5, it appears that fsolve will get trapped in that local hole. It cannot escape, because fsolve cannot look at the function and understand the only real root lies at x==8.
This is very possibly what fsolve is telling you.
SQUEEZING the tolerance tighter will NOT help!!!!!!!!! You cannot get blood from a rock by squeezing your fingers tighter around the rock. Yes, you may find some blood, but the blood will have come from your own fingers, not the rock.
If a root exists, you will need to choose better, intelligently chosen starting values.
You may find that using a different tool, perhaps GA, or multi-start may help. However a 36 dimensional space is a big place to search around. INTELLIGENTLY CHOSEN STARTING VALUES ARE THE BEST THING.
  6 Comments
Alex Sha
Alex Sha on 27 Jan 2021
Hi, have you ever try some functions with global optimization algorithms? both fsolve and lsqcurvefit adopt local optimization algorithms, it's why the guess of initial start values is so important, it leads to also the result of local solutions for even slightly complicated cases as you are currently experiencing. You may have a try some other packages with global optimization, like Baron, Lingo or 1stOpt.
Omar Khalifa
Omar Khalifa on 27 Jan 2021
True that. The solution is very subjective to the initial guesses. The lsqnonlin yielded imaginary numbers for physical solutions, which is definitely not what I am looking for. I will see if any of the global optimization packages would solve the issue. Thanks for the suggestion!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!