What is wrong with my code for the bisection method?
1 回表示 (過去 30 日間)
古いコメントを表示
x=my_bisect(@(x)x-2.5).*exp(-0.5*(x-2).^2)+0.2;[-1,0],1e-5)
a=I(-1);
b=I(0);
msg=sprintf('invalid choice of interval');
if f(a)*f(b)>0
disp(msg)
m=[(a+b)/2];
return
end
Can I just write my function in x=... above as is or do I have to have it saved in another .m file?
My syntax above is x = my_bisect(f,I,tol)
The error message that comes up is: Error: Unbalanced or unexpected parenthesis or bracket.
edit 1: changed my typo. Thanks Image Analyst.
0 件のコメント
回答 (1 件)
Image Analyst
2014 年 10 月 8 日
min_bisect() is different than my_bisect(). Did you make a typo?
2 件のコメント
Image Analyst
2014 年 10 月 8 日
And it barely looks anything like the corrected anonymous function I gave you in http://www.mathworks.com/matlabcentral/answers/157702#answer_154243
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!