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?
显示 更早的评论
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 个评论
Walter Roberson
2016-2-18
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.
采纳的回答
更多回答(1 个)
Walter Roberson
2016-2-18
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 MuPAD 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
