What does fzero take as input for the function?
1 view (last 30 days)
Show older comments
If i have a function that starts as follows:
function [y,index] = findsmode(x)
and if i then use
sigma=fzero(@findmode,500);
then what does the function findmode take as input x?
Also, if i put
disp(*)
within the function file with * being some variable calculated in the function, why does the value show up in my command window multiple times, while it is not being iterated.
I hope someone can explain this to me
0 Comments
Accepted Answer
Steven Lord
on 22 Jan 2021
then what does the function findmode take as input x?
fzero will call your findmode function repeatedly with various values as it tries to search for a root of findmode.
You can kind of think of this like someone walking along a path. They look left one pace to determine if that location on the path is higher or lower than where they are, then look right one pace to determine the same thing, decide which way to step based on whether they're higher or lower than their destination, and repeat this process.
why does the value show up in my command window multiple times, while it is not being iterated.
You may not have a loop inside your function but fzero will call your function repeatedly as part of its search.
3 Comments
Steven Lord
on 22 Jan 2021
Use optimset to set the 'Display' and/or 'OutputFcn' options.
fzero(@sin, 1, optimset('Display', 'iter'))
As far as I'm aware there isn't a predefined OutputFcn that plots x and the value of the function at the x value for each iteration but it is possible to write one. See this documentation page for more information.
More Answers (0)
See Also
Categories
Find more on Entering Commands 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!