Borrar filtros
Borrar filtros

How to write a singler for a code that needs to use Fsolver in a loop ?

2 visualizaciones (últimos 30 días)
Hi All
is there a way to avoid writing one separate mfile for fsolver function to call it in a loop from the main mfile ?

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Mzo. de 2020
You can pass fsolve a function handle. That can be an anonymous function or it can be the handle to a real function. If it is the handle to a real function it must be @ followed by the name of a function that is visible to the calling code, including possibly the name of a function in the same file, or the name of the first function in another file, or a function that is a static method of a loaded class, or (I think) a function that is inside a package reference.
Since R2016b, it has been permitted to store a function at the end of a script. The script can make an @ reference to the function. Versions before that did not have that option and so for those older versions, you effectively needed a different mfile if you wanted a real function instead of an anonymous function.
There is also an old syntax that permits passing the name of a function as a character vector. In very early releases, the current file was searched for those functions too, but for more than a decade, this syntax has only been able to find functions that are the first function in their mfile (and, really obscurely, some package references in some cases.)

Más respuestas (0)

Categorías

Más información sobre Function Handles en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by