너무 간단한 로직이어서 뭘로 구현하든 큰 차이가 없으니 매트랩 소스만 를 올린다.
function root = Bisection(start_point, end_point)
% Exit Condition %
tolerance = 1.0e-20;
numofsteps = 100;
mid_point = start_point + (end_point - start_point) / 2.0;
error = abs(mid_point - start_point);
value = target_func(mid_point);
i = 0;
while (error > tolerance) && i < numofsteps
if( value * target_func(end_point) > 0)
end_point = mid_point;
elseif ( value * target_func(end_point) < 0 )
start_point = mid_point;
end;
mid_point = start_point + (end_point - start_point) / 2.0;
value = target_func(mid_point);
error = abs(mid_point - start_point);
i = i + 1;
end
% outpout %
i
format long
root = mid_point
error
end
function value = target_func(x)
value = x^5 - 5.5*x^4 + 12.1*x^3 - 13.31*x^2 + 7.3205*x - 1.61051;
end
% Exit Condition %
tolerance = 1.0e-20;
numofsteps = 100;
mid_point = start_point + (end_point - start_point) / 2.0;
error = abs(mid_point - start_point);
value = target_func(mid_point);
i = 0;
while (error > tolerance) && i < numofsteps
if( value * target_func(end_point) > 0)
end_point = mid_point;
elseif ( value * target_func(end_point) < 0 )
start_point = mid_point;
end;
mid_point = start_point + (end_point - start_point) / 2.0;
value = target_func(mid_point);
error = abs(mid_point - start_point);
i = i + 1;
end
% outpout %
i
format long
root = mid_point
error
end
function value = target_func(x)
value = x^5 - 5.5*x^4 + 12.1*x^3 - 13.31*x^2 + 7.3205*x - 1.61051;
end
'Finance > numerical methods' 카테고리의 다른 글
Horner's Rule (0) | 2009.10.27 |
---|---|
IMSL 6.0 설치 - 비공개 (0) | 2008.02.02 |
IMSL 6.0 설치 및 VS2005 환경 설정(static library , dll) (0) | 2008.02.02 |
수치해석 주요 내용 (0) | 2007.12.18 |