Doubt regarding the fzero command.

1 次查看(过去 30 天)
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