Friday, 18 November 2011

MATLAB : Thuật toán chia đôi .

function s = solve_equation (f, a, b, e)
while abs ( subs(f, a) * subs(f, b) ) > 2*e
half = ( a+b )/2 ;
if ( subs(f,a) * subs(f, half) ) <= 0
b = half ;
else
a = half ;
end
end
s = a;