I cannot the error in the bisection method...
Show older comments
Hi! I am trying to detect why my code doesn´t work properly.
This is the code.
f = @(x) x^3 + 2*x^2 + 10*x - 20;
a = 0;
b = 1;
eps_f = 10e-10;
eps_x = 10e-10;
maxits = 100;
[x, n, error] = biseccion(f,a,b,eps_x, eps_f, maxits)
function [x,n,error] = biseccion(f,a,b,eps_x, eps_f, maxits);
x0 = a;
x1 = b;
n = 0;
error (1) = abs(x1-x0);
while n < maxits && (error(n+1) > eps_x || abs(f(x0)) > eps_f)
x = 0.5 * (x0 + x1);
if f(x0)*f(x) < 0
x1 = x;
else
x0 = x;
end
n = n+1;
error(n+1) = abs(x1-x0);
end
end
Accepted Answer
More Answers (0)
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
