f(x) = x^2 - 200x + 9999.9999 by using bisection method in matlab please help me. interval [0, 10000]

3 views (last 30 days)
% 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;

Answers (2)

Askic V
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)

Steven Lord
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.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!