i have problem in bisection method.

1 回表示 (過去 30 日間)
Nugraha Septiawisal
Nugraha Septiawisal 2021 年 3 月 16 日
回答済み: Steven Lord 2021 年 3 月 16 日
i'm having a problem while using "inline" for bisection, here are my script
function c=bisection(f, a, b, maxit,tol)
if nargin < 5, tol=1e-4; end
if nargin < 4, maxit=100; end
if f(a)*f(b)>0
c='failure';
return
end
disp(' n a b c (b-a)/2')
for i=1:maxit
c=(a+b)/2;
if f(c)==0
return
end
fprintf('%d \t %d \n', i, a, b, c, (b-a)/2)
if (b-a)/2 < tol
return
end
if f(b)*f(c)>0
b=c;
else a=c;
end
end
c='failure';
and this is i got in command window
please help :))

回答 (1 件)

Steven Lord
Steven Lord 2021 年 3 月 16 日
Stop using inline. Use function handles or anonymous functions instead.
f = @sin;
g = @(x) cos(x+1);

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by