How do you stop fsolve?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!