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

2 次查看(过去 30 天)
% 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;

回答(2 个)

Askic V
Askic V 2022-12-13
编辑:Askic V 2022-12-13
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 2022-12-13
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.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by