Problem with solving equation with 'FSOLVE'

6 ビュー (過去 30 日間)
ByungChul Min
ByungChul Min 2016 年 10 月 4 日
コメント済み: Hongchu Yu 2019 年 6 月 18 日
Hello,
I am solving a system of equations with FSOLVE. I generated starting points with
x0 = rand(2,1);
However, for some x0s, there's an error message saying
Error using trustnleqn (line 28)
Objective function is returning undefined values at initial point. FSOLVE cannot continue.
It seems that for some starting points, the fsolve cannot find solutions.
However, I want FSOLVE to immediately retry with a new random starting point rather than stopping and showing an error message. How can I do that?

採用された回答

dpb
dpb 2016 年 10 月 4 日
Don't blame fsolve; the issue is you're providing solution points as initial guesses that aren't feasible for the system equations. Better solution would be to ensure the points are feasible before calling fsolve.
But, you can just try the brute-force route of putting the guess and solution calls inside a try...catch block and just keep trying...it might just work out ok.
  2 件のコメント
ByungChul Min
ByungChul Min 2016 年 10 月 4 日
Thank you very much. try-catch did the job.
Hongchu Yu
Hongchu Yu 2019 年 6 月 18 日
Hi, Could you share me with the ecoding with try-catch to find feasible initial solution? Thanks a lot.

サインインしてコメントする。

その他の回答 (1 件)

Jakub Rysanek
Jakub Rysanek 2016 年 10 月 4 日
To me it appears that the initial conditions to your optimization problem must lie within a specific, perhaps bounded, region. For example, you cannot ask what is the zero point of
log(x)
and start with the initial guess at x=-1, because log(.) function is defined in the positive domain only.
fsolve(), just like many other optimization routines must always start within the feasible region.

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by