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;
0 个评论
回答(2 个)
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)
0 个评论
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!