What does fzero take as input for the function?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Steven Lord
il 22 Gen 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 Commenti
Steven Lord
il 22 Gen 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Entering Commands in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!