Bisection Method Issues/Help

조회 수: 4 (최근 30일)
SB
SB 2012년 11월 19일
Hi people, I'm having a bit of an issue with my Bisection Method Algorithm, which I understand conceptually, but it doesn't quite work with my code. My outputs are the final root, absolute value of the function at the root, number of iterations and all the midpoints generated through each iteration. Here's my code so far:
% function [r,rHist,N,fRoot] = bisectionE7(fHan,xL,xR,fTol,iterMax)
k= 0; % initialize iteration counter
fxL = feval(fHan,xL);
fxR = feval(fHan,xR);
sfxL = sign(fxL);
sfxR = sign(fxR);
if (sfxL*sfxR > 0)
r=[];
rHist=[];
N=[];
fRoot=[];
end
while (k <= iterMax)
% use midpoint as the iterate
c = (xL+xR)/2;
fc = feval(f,c);
sfc = sign(fc);
if ((xR-xL)<2*fTol | fc == 0)
x = c;
return
elseif (sfxL*sfc < 0)
xR = c;
else
xL = c;
end
k = k+ 1;
end
% if this while loop terminates before returning the root
disp(' max number of iterations reached ... ')
x = xL;
  댓글 수: 2
John Petersen
John Petersen 2012년 11월 20일
Okay, so the code doesn't work. What is your question? Where does it fail? What parts work? Try bisecting the problem to help you find where you are having a problem and then someone will be more able and willing to help.
SB
SB 2012년 11월 21일
It's alright, I figured out how to fix it, thank you though!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by