I keep getting an error stating that fsolve has stopped because it has exceeded the function evaluation limit.

조회 수: 2 (최근 30일)
Here is my code
%%Fsolve portion
fun = @root2d;
x0 = [10000,1];
x = fsolve(fun,x0);
%%Actual functions
function F = root2d(x)
F(1) = (24/(x(1)))+(3/(sqrt(x(1)))) - x(2) + 0.34; %%first function
F(2) = x(1) - ((371e-4)/.0014)*sqrt((4*9.81*(6800)*1000*(371e-4))/(3*x(2))); %%2nd function
end
Every time I run this code, I run into that error that the function evaluation limit has been reached. What can I do to solve this?
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 4월 8일
KALYAN ACHARJYA is correct to refer to that solution.
You will need about 2000 iterations and about 6000 function evaluations.

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2018년 4월 8일
편집: John D'Errico 2018년 4월 8일
These equations are rather numerically nasty. So fsolve may well have problems.
x = sym('x',[1 2]);
F(1) = (24/(x(1)))+(3/(sqrt(x(1)))) - x(2) + 0.34; %%first function
F(2) = x(1) - ((371e-4)/.0014)*sqrt((4*9.81*(6800)*1000*(371e-4))/(3*x(2))); %%2nd function
xsym = solve(F)
xsym =
struct with fields:
x1: [4×1 sym]
x2: [4×1 sym]
There are 4 solutions that solve found, only two of which are real. And one of those real solutions was apparently not a solution at all.
vpa(xsym.x1)
ans =
81273.682385843104986453160925862
83807.81449859714950662847111925
- 82572.409341874106485295141282072 - 1268.168832976111876747928305322i
- 82572.409341874106485295141282072 + 1268.168832976111876747928305322i
vpa(xsym.x2)
ans =
0.35081846126435722534542088738111
0.32992352460468702550608076574237
0.33962925563058826267375383409956 - 0.010434692599468016237426647495723i
0.33962925563058826267375383409956 + 0.010434692599468016237426647495723i
Taking those possible solutions, we see that the first is indeed a root, while the second real solution is indeed spurious, thus not a root.
X = vpa([xsym.x1(1),xsym.x2(1)])
X =
[ 81273.682385843104986453160925862, 0.35081846126435722534542088738111]
subs(F,x,X)
ans =
[ 0, 2.4074124304840448163199724282312e-35]
X = vpa([xsym.x1(2),xsym.x2(2)])
X =
[ 83807.81449859714950662847111925, 0.32992352460468702550608076574237]
subs(F,x,X)
ans =
[ 0.020725689744471398174727540556394, 0]
  댓글 수: 5
Walter Roberson
Walter Roberson 2023년 9월 24일
Are you trying to proceed purely numerically using fsolve() ? Or are you trying to find closed-form or indefinite precision solutions using Symbolic Toolbox solve? Or are you trying to find higher-precision numeric solutions using Symbolic Toolbox vpasolve ?
If you are doing numeric solutions using fsolve() then you would provide it with an options structure that increased the maximum iterations and the maximum number of function evaluations. For particularly "bumpy" systems it can take sometimes millions of evaluations to find a solution, and that can add up to a fair bit of time.
vpasolve() is typically slower than fsolve() -- but not always. There are some functions that vpasolve() is able to reason about to pick more likely solution spaces. There are also cases where double precision calculations are not stable enough, leading to long searches using fsolve() but the extended precision of vpasolve() might happen to give a system stable enough for relatively direct solution.
solve() is typically the slowest of the possibilities... but again not always

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Partial Differential Equation Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by