What does fzero take as input for the function?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
matlabber
el 22 de En. de 2021
Comentada: matlabber
el 22 de En. de 2021
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 comentarios
Respuesta aceptada
Steven Lord
el 22 de En. de 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 comentarios
Steven Lord
el 22 de En. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Variables 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!