update guess in fsolve
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to solve f(x) = 0 using x0 as a guess. I can use fsolve. Let's assume that given the guess the exit flag is not 1 (equation not solved). What would be the most straighforward way to update my initial guess?
2 Kommentare
Walter Roberson
am 16 Feb. 2025
It is normal for the exit flag is positive (1 through 4), unless you have set options to make most tolerances extremely small.
Antworten (2)
Star Strider
am 16 Feb. 2025
I am not certain what you are actually asking.
If possible (if an equation can be plotted), I usually begin by plotting iit to get an idea of its characteristics. I then use an initial estimate based on what I learn from the plot.
There are a number of apppropriate functions in the Global Optimization Toolbox (my favourite being ga) that will themselves iterate the initial guess until they find the best one. This works even if an equation cannot be plotted.
.
2 Kommentare
Star Strider
am 16 Feb. 2025
My plotting approach will not work with n equations and n unknowns.
Genetic algorithms are not difficult to write, however writing and debugging a complete version involving crossovers and mutations can be time-consuming.
I do not understand a reason to need to update the fsolve initial guess. I would just use the optimset function to increase the number of iterations and the number of function evaluations to allow fsolve to converge to an acceptable result.
Perhaps:
opts = optimset(MaxIterations=1000, MaxFunctionEvaluations=50000);
and then pass that as the third argument to fsolve. Change those as necessary for your problem.
.
John D'Errico
am 16 Feb. 2025
Um, no, You cannot always find a way to "update" your initial guess for fsolve. One can even prove this to be true.
You can change your initial guess. Simplest is to use a multi-start scheme, which will work even wothout the global optimization TB. There is nothing magic in multi-start. Just generate a random start point, and see if you get a solution you like. If not, keep trying random points inside the domain of interest until you are happy, well, until you get lucky.
However, there is no simple (or any complicated scheme either) to infer a better start point for an optimization problem, even if you can try to base it on a previous set of iterations. Again, we can prove that must fail. So no. There is no straightforward way to do what you want.
Unfortunately, from what you say, this is a system of nonlinear equations. And that means they can be arbitrarily nasty. They can have large domains where no matter what the start point in that domain, fsolve will always converge to a non-solution, and even if a solution does exist, the set of start points that will converge to the solution you want will be arbitrarily small.
So I'm sorry, but want what you want, there is no magic you can use. At best, you want to use global optimization tools, which themselves are not gauranteed to converge to a happy place. (But they are more likely to do so, on difficult problems.) Lacking that, just use a home-brewed multi-start method, calling fsolve repeatedly with random start points..
5 Kommentare
Torsten
am 17 Feb. 2025
If the function does not vary much from step to step, use the solution of the i-th call to "fsolve" as initial guess for the (i+1)th call.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!