필터 지우기
필터 지우기

Doubt regarding the fzero command.

조회 수: 1 (최근 30일)
Douglas Alves
Douglas Alves 2014년 6월 5일
편집: José-Luis 2014년 6월 5일
Hi guys,
What does it mean when we write in a code P0 = fzero (@somefunction, [1, 25]). Does it mean search for an answer in the interval from 1 to 25 ? I usually set one value in which fzero start its search for the solution.
That`s the actual line that`s puzzling me
P0=fzero(@(P0) estimateSurfacePressure(P0,false,extPar), [1 25]);
The last thing is estimateSurfacePressure is a .m file the way fzero goes in this file is pretty weird for me. What does @(P0) mean? It looks somewhat like those function we create like this y = @(x) [x^2] is there something to do with it?
Thank you very much for helping.

채택된 답변

José-Luis
José-Luis 2014년 6월 5일
편집: José-Luis 2014년 6월 5일
It means that the function estimateSurfacePressure() is in the path and will be evaluated for different values of PO until one yielding zero value has been found.
It also means that estimateSurfacePressure() returns a scalar.
  댓글 수: 2
Douglas Alves
Douglas Alves 2014년 6월 5일
but why is it written like
P0=fzero(@(P0) estimateSurfacePressure(P0,false,extPar), [1 25]);
I would've written as
P0=fzero(estimateSurfacePressure(P0,false,extPar), [1 25]);
what's the @(P0) for ? I know that @ calls functions but this file is not actually an actual function such as y=@(x) [x^2] ;
and is it right that P0 will be varied until I have an answer but in the range [1,25] ?
Thank you Jose.
José-Luis
José-Luis 2014년 6월 5일
편집: José-Luis 2014년 6월 5일
Yes, it will look for an answer in the [1 25] interval.
fzero() takes a scalar-valued function handle as first argument. estimateSurfacePressure() takes three arguments but the author of the code only wanted to find the roots when one of them varies. Therefore he uses a function handle that allows him to let only P0 vary.
With the @ you are creating an anonymous function, that takes only one argument: P0 and is then passed to fzero().
Please read the documentation of function handles for further information.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by