How to get fsolve return number of iterations

25 ビュー (過去 30 日間)
ttopal
ttopal 2017 年 1 月 22 日
コメント済み: ttopal 2017 年 2 月 10 日
Hi all,
Yet another fsolve question. I am trying to compare now various root finding functions I have as well as fsolve.
In the help file it shows this;
[x,fval,exitflag,output] = fsolve(fun,x0,options)
and this
output.funcCount
so I would like to have this;
[root,output] = fsolve(myfun,x0,options);
count = output.iterations
i receive this;
Struct contents reference from a non-struct array object.
Error in zerotest (line 57)
output.iterations
What I am missing?
Thanks a lot.

採用された回答

ttopal
ttopal 2017 年 1 月 22 日
Okay. So it turns out it needs this;
[x,fval,exitflag,output] = fsolve(fun,x0,options)
output.iterations
you have to return fval and exitflag even if you dont use them.
  2 件のコメント
Stephen23
Stephen23 2017 年 1 月 22 日
編集済み: Stephen23 2017 年 1 月 22 日
"you have to return fval and exitflag even if you dont use them."
It is not necessary to allocate outputs if you do not want them:
[x,~,~,out] = fsolve(...);
out.iterations
ttopal
ttopal 2017 年 2 月 10 日
Thanks Stephen,
I did not know that either.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by