Fsolve with different combinations of parameters
10 views (last 30 days)
Show older comments
Hi,
I have a system of 11 nonlinear equations and 11 unknown variables that I would like to solve for. The nonlinear equations also depend on a set of parameters. Using the fsolve function, I keep getting the message:
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 8.000000e+03.
I therefore want to nest the fsolve function inside a set of loops over different combinations of parameter values to see if I can get a solution with a different set of parameters. What is the generic code for doing so?
Thank you very much!
0 Comments
Accepted Answer
Torsten
on 23 May 2023
Edited: Torsten
on 23 May 2023
Varying the initial values for the unknown variables should be the first step. Try "MultiStart".
Varying parameters is usually done via nested for-loops where each loop runs over the values of one of the parameters.
6 Comments
Torsten
on 24 May 2023
Edited: Torsten
on 24 May 2023
Since z is a solution vector with more than one element, you will have to use
z(:,ip1,ip2) = fsolve(@(x)FUNS(x,parameter),zg);
instead of
z(ip1,ip2) = fsolve(@(x)FUNS(x,parameter),zg);
If you still get the error message
Failure in initial objective function evaluation. FSOLVE cannot continue.
try to evaluate your function with the initial values zg before calling "fsolve":
FUNS(zg,parameter)
More Answers (1)
Walter Roberson
on 23 May 2023
Increase the maximum evaluations instead.
opts = optimoptions(@fsolve, 'MaxFunctionEvaluations', 1e5, 'MaxIterations', 1e5);
[bestx, fval, exitflag] = fsolve(HANDLE, x0, opts)
0 Comments
See Also
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!