Error in Bisection Method
이전 댓글 표시
I used a code for bisection method, which supposed to be working, unfortunately it´s not and I do not know what is the problem. This code also includes user defined precision and a counter for number of iterations. The error I´m getting is for the last line in the code: Undefined function or variable 'c'.
a=-5;
b=0;
tol = input('What precision would you like? ','s')
fa=a^3-20+exp(a);
fb=b^3-20+exp(b);
counter=1
while abs(b-a) > tol
c=(a+b)/2;
fx = c*c-2;
if fa*fc<0
b=c;
fb=fc;
elseif fb*fc<0
a=c;
fa=fc;
else
break
end
fprintf('Just finished iteration #%d\n', counter);
counter=counter+1;
end
x=c;
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!