Doubt regarding the fzero command.

3 views (last 30 days)
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.

Accepted Answer

José-Luis
José-Luis on 5 Jun 2014
Edited: José-Luis on 5 Jun 2014
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 Comments
Douglas Alves
Douglas Alves on 5 Jun 2014
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 on 5 Jun 2014
Edited: José-Luis on 5 Jun 2014
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Optimization in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!