Doubt regarding the fzero command.

1 visualizzazione (ultimi 30 giorni)
Douglas Alves
Douglas Alves il 5 Giu 2014
Modificato: José-Luis il 5 Giu 2014
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.

Risposta accettata

José-Luis
José-Luis il 5 Giu 2014
Modificato: José-Luis il 5 Giu 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 Commenti
Douglas Alves
Douglas Alves il 5 Giu 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 il 5 Giu 2014
Modificato: José-Luis il 5 Giu 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by