필터 지우기
필터 지우기

How to make my bisection method more accurate?

조회 수: 4 (최근 30일)
Joe
Joe 2013년 4월 14일
I have constructed a root-finding function based on the bisection method. The function works, however, the roots it gives me aren't as accurate as I want them to be. They are off of about 1e-4 when compared to the exact roots. I don't understand how I can make it more accurate. Can someone please help. Here's my code:
function root = bisection(f,a,b,tol)
if sign(f(a))==sign(f(b))
error('a and b do not bracket the root');
end
j = 1;
while abs(0.5*(b-a)) >= tol
root = 0.5*(a+b);
j = j+1;
if sign(f(a))==sign(f(root))
a = root;
else
b = root;
end
end
end

채택된 답변

James Tursa
James Tursa 2013년 4월 15일
편집: James Tursa 2013년 4월 15일
Change tol to a smaller value. E.g.,
>> f = @sin
f =
@sin
>> a = -.1
a =
-0.1000
>> b = .2
b =
0.2000
>> bisection(f,a,b,1e-4)
ans =
4.8828e-005
>> bisection(f,a,b,1e-10)
ans =
4.6566e-011
>>

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by