How to write a singler for a code that needs to use Fsolver in a loop ?
1 view (last 30 days)
Show older comments
farzad
on 20 Mar 2020
Answered: Walter Roberson
on 20 Mar 2020
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 ?
0 Comments
Accepted Answer
Walter Roberson
on 20 Mar 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.)
0 Comments
More Answers (0)
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!