How to get fsolve return number of iterations

조회 수: 24 (최근 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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by