f(x) = x^2 - 200x + 9999.9999 by using bisection method in matlab please help me. interval [0, 10000]
2 views (last 30 days)
Show older comments
% Bisection Algorithm
% Find the root of f(x) = x^2 - 200*x + 9999.9999 from o to 10000.
f = @(x) (x^2 - 200*x + 9999.9999);
a = input('Please enter lower limit, a: ');
b = input('Please enter upper limit, b: ');
tol = input('Please enter tolerance, tol: ');
fa = f(a); fb = f(b);
i = 1;
while i <= n
c = (b - a) / 2.0;
p = a + c;
fp = f(p);
if abs(fp) < 1.0e-20 | c < tol
fprintf('\nApproximate solution p = %11.8f \n \n',p);
break;
0 Comments
Answers (2)
Askic V
on 13 Dec 2022
Edited: Askic V
on 13 Dec 2022
Is there something that is missing?
f = @(x) (x^2 - 200*x 9999.9999);
In addition to that, it seems to me that user will have a hard time entering the proper initial interval, based on how function actually looks like:
f = @(x) (x.^2 - 200.*x + 9999.9999);
n = 90:0.1:110;
y = f(n);
plot(n,y)
0 Comments
Steven Lord
on 13 Dec 2022
If you look at the pseudocode on Wikipedia, it has two if statements inside the while loop. You have one. Where's the other?
For debugging purposes, you might want to display the values of a, b, c, p, and fp inside the loop and try to solve the problem shown on that Wikipedia page (). Compare your values for the two endpoints, the middle point, and the function value with the ones shown on the Wikipedia page.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!