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!
