define a stopper in f-solve loop

2 Ansichten (letzte 30 Tage)
milad
milad am 4 Jul. 2015
Kommentiert: Walter Roberson am 5 Jul. 2015
hello my dear friends I want to solve a nonlinear equation by F-solve, in which a variable will changed in each loop, but I want to stop the iterative process when the answer of F-solve will be " equation solved, but inaccuracy is possible" or " no solution found", and print the last solution. what should I do exactly? could you please help me Thank you!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Jul. 2015
while true
[x, fval, exitflag] = fsolve(....);
if exitflag ~= 1
break;
end
end
any of the exit statuses other than +1 could be interpreted as inaccuracy. That can include that the search was going well but that it was taking more iterations than you configured to allow, and can include that the search noticed that round-off error is interfering with pinning down the solution to within the tolerance you requested. Generally speaking, negative exit statuses are the "hard" exits indicating that there is no solution to be found in the area, and positive exits other than +1 indicate that you are running into difficulty with numeric accuracy but that there is likely a solution "nearby".
  2 Kommentare
milad
milad am 5 Jul. 2015
Hi Walter. The answer you give is so useful, but it stops the F-solve iterative process even for "equation solved, f-solve stalled". Also the first term 'While' take the problem to an infinitive loop if the exit-flag is equals to 1.
Walter Roberson
Walter Roberson am 5 Jul. 2015
There is no specific exit status for "equation solved, but inaccuracy is possible". Any positive exit status other than +1 could be interpreted as falling into that category. Anyhow, you can use (for example)
if ~ismember(exitflag, [1, 3, 4])
If you prefer a "for" loop then use a "for" loop. The "break" remains the same.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by