so you're saying i should hard code it? or just for the sake of testing purposes.
Code:
%Bisection Method
a = 0;
b = 0;
TOL = 0;
N0 = 0;
p = 0;
i = 1;
a = input('Please enter starting endpoint "a" for the Bisection Method');
b = input('Please enter starting endpoint "b" for the Bisection Method');
TOL = input('Please enter desired tolerance for the Bisection Method');
N0 = input('Please enter maximum number of iterations for the Bisection Method');
FA = f(a);
while i <= N0
p = a + (b - a) / 2;
FP = f(p);
if FP = 0 | (b - a) / 2 < TOL;
disp(sprintf('%5.6f', p);
else i = i + 1;
if FA * FP > 0;
a = p;
FA = FP;
else b = p;
end
end
end
disp('Method failed after N0 iterations, N0 =', N0);
Quote:
for one... you should only say that the method has failed AFTER you are done with the loop. check your logic. I'm not going to do that for you.
|
i changed it, thanks for pointing that out for me. does that make sense now?
Quote:
Use a Boolean variable to keep track of whether the SUCCESS conditions have been met. Terminate the loop when you have succesfully done it. probably easier to do in in a WHILE loop in this case.
|
there is a boolean checking...
Code:
if FP = 0 | (b - a) / 2 < TOL;
disp(sprintf('%5.6f', p);
end
Quote:
Store the result as a variable, don't print it out, and make this function output that variable
|
i thought i was storing it as a variable p, which i do print with the disp(sprintf function...
thanks for your help. oh yeah, does the last function that displays the message using the disp(sprintf make sense? is it wrong?