Skip lsqnonlin run if error

2 ビュー (過去 30 日間)
Xen
Xen 2017 年 6 月 28 日
コメント済み: Xen 2017 年 6 月 28 日
Hi guys. I am using lsqnonlin for some fitting, and I am running a loop where I change the initial parameter values to determine the best ones based on the residuals; this is because the fitting is not as robust as I expected and it gives different results for different initial parameters (I would love to hear a suggestion for this as well...!). So, for some combinations of parameters it fails and gives this error:
Error using levenbergMarquardt (line 16)
Objective function is returning undefined values at initial point. lsqnonlin cannot continue.
How can I make the process recognize the error, skip this run and proceed with finishing the loop?
Thanks

採用された回答

Alan Weiss
Alan Weiss 2017 年 6 月 28 日
If you have Global Optimization Toolbox, then use MultiStart to run lsqnonlin several times. MultiStart automatically continues if it encounters NaN or Inf values.
Otherwise, it is not too hard to program up this kind of functionality for yourself. If you have finite bounds on all parameters, you can repeatedly use
x0 = lb + rand(size(lb)).*(ub - lb)
as initial points. You can use a try/catch statement to continue after encountering an error.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Xen
Xen 2017 年 6 月 28 日
The try/catch method did the trick! I will try the other suggestions soon. Thanks Alan.

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

その他の回答 (0 件)

カテゴリ

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