How do you stop fsolve?
2 ビュー (過去 30 日間)
古いコメントを表示
Suppose I have the following call
[x,fval] = fsolve(@myfun,x0)
The function which I wish to solve is given by myfun, which, in addition to computing the values myfun(x0), also determines whether the solver should continue or quit. For example,
function F = myfun(x)
if something happens
stop = true;
end
F = x.^2 - 10;
end
How do I send an immediate quit message to fsolve? There are two requirements: (i) the program which calls fsolve cannot stop itself (I can't use an error command), and (ii) I need to know that fsolve had prematurely stopped.
One 'almost' solution is to use optimset('OutputFcn', @myout), and then set stop = true within the output function. fsolve then spits out an exitflag which states that the solver stopped due to the output function. But there are two problems with this: (i) it's called only at each iterate of fsolve, NOT at every evaluation of the function, and (ii) the output function does not know about the variables within the fsolve function (I need this scope).
What I require is something like the Events option for ode solvers. This allows the ODE solver to quit once a certain condition is met.
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!