bisection method - can't see error in code
조회 수: 1 (최근 30일)
이전 댓글 표시
I am unable to pin point the error in my code of my funtion for the bisection method, any help would be greatly appreciated
function [rootx]=bisect(fhandle,a,b,epsilon)
rootx=[];
Fa=fhandle(a);
Fb=fhandle(b);
m=((b-a)/2);
Fm=fhandle(m);
while abs(m)>epsilon ;
if Fb*Fm <0
a=m
else
b=m
end
end
return m=((a+b)/2)
end
rootx
댓글 수: 2
채택된 답변
James Tursa
2012년 10월 3일
1) Google "bisection method"
2) Go to the 1st Wiki link
3) Look at the pseudo-code posted there
4) Compare that to your code to discover your errors, paying special attention to what Matt J said about not updating your variables within your loop.
댓글 수: 0
추가 답변 (2개)
Babak
2012년 10월 3일
In the while loop
while abs(m)>epsilon ;
if Fb*Fm <0
a=m
else
b=m
end
end
you are not changing m and you are trying to check the abs(m)
I think you meant
m=a
and
m=b
instead...
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!