How do I implement a Matlab function, findtbracket.m, that, when a random function is inputed, the file will find the initial interval of the function?
Mostrar comentarios más antiguos
The assignment asks us to implement a Matlab file, findtracket.m, of the form
function [a,b]=findbracket(f,X0)
% f: function handle f(x) to find a zero for
% x0: starting point/center of interval containing zero
to try to find an initial interval [a,b] containing the input x_0 and bracketing the zero of f(x)
Also, the function should begin with a=b=x_0 and a step size del=2^(-k) choosen so that
fl(x_0-del)<fl(x_0-del/2)=x_0
While sgn f(a)=sgn f(b), decrease a by del, increase b by del, evaluate f(a) and f(b) and double del.
This is what I have so far (I am a Matlab newbie):
function [a,b]=find bracket(f,x0)
a=x0;
b=x0;
while 1
a=a-dx;
if f(a)*f(b)<0,break;
b=b+del;
if f(a)*f(b)<0, break;
end
1 comentario
Walter Roberson
el 18 de Feb. de 2016
The PNG image asks for "findbracket" not "findtracket".
You are not showing us how you invoke the code. And for sure you will need del and/or dx to be defined to use your code.
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 18 de Feb. de 2016
0 votos
It is not acceptable to have a space in the name of a function. "findbracket" not "find bracket".
Your code does not initialize dx or del. It appears to me from the PNG that dx and del should be the same value.
Categorías
Más información sobre MuPAD en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
