False Position method. How many itinerations should it take to find the root?

3 visualizaciones (últimos 30 días)
Hi! I am programming the false position method. However, with 100 itinerations, my program cannot find a root with an error smaller than 10e-10 nor 10e-6.
Is this normal, or is it just that my program that does not work properly?
Find attached the code.
Hope you can help me!
  2 comentarios
Dyuman Joshi
Dyuman Joshi el 6 de Abr. de 2023
Please post the code, instead of posting the picture of the code.
From the looks of it, it seems 100 iterations are not enough to find a root with that tolerance.
Also note the different between
10e-10
ans = 1.0000e-09
1e-10 %10^x is equal to 1ex
ans = 1.0000e-10
llucia
llucia el 6 de Abr. de 2023
Thanks! So the code is right, then? I mean, the problem is that it takes more itinerations to find the root right?

Iniciar sesión para comentar.

Respuestas (1)

Dyuman Joshi
Dyuman Joshi el 6 de Abr. de 2023
Editada: Dyuman Joshi el 6 de Abr. de 2023
A correction is needed -
while n<maxits && error(n+1)>eps_x && abs(f(x0))>eps_f
%^here
If any of the condition is met, exit the loop
%I'm running it as a script with some changes
f = @(x) x^3 + 2*x^2 + 10*x - 20;
x0=0;x1=1;
error=abs(x1-x0);
n=0;
while error > 1e-10 && abs(f(x0)) > 1e-10
a=f(x0);b=f(x1);
x = (x0*b-x1*a)/(b-a);
if a*b<0
x1=x;
else
x0=x;
end
error=abs(x1-x0);
n=n+1;
end
n
n = 14
format long
x
x =
1.368808107821373
f(x)
ans =
0
  2 comentarios
Torsten
Torsten el 6 de Abr. de 2023
A correction is needed -
while n<maxits && error(n+1)>eps_x && abs(f(x0))>eps_f
Why ? I found the first version quite plausible. As long as not both conditions are met, the root is questionable and should be improved. And the code works as posted.
f = @(x)x.^3+2*x.^2 + 10*x -20;
a = 0;
b = 1;
eps_x = 1e-10;
eps_f = 1e-10;
maxits = 100;
[x n error] = RegulaFalsa1(f,a,b,eps_x,eps_f,maxits)
x = 1.3688
n = 14
error = 1×15
1.0000 0.5385 0.1882 0.1705 0.1697 0.1697 0.1697 0.1697 0.1697 0.1697 0.1697 0.1697 0.1697 0.1697 0
function [x,n,error] = RegulaFalsa1(f,a,b,eps_x,eps_f,maxits)
x0 = a;
x1 = b;
n = 0;
error(1) = abs(b-a);
while n < maxits && (error(n+1) > eps_x || abs(f(x0)) > eps_f)
x = (x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
if f(x0)*f(x1) < 0
x1 = x;
else
x0 = x;
end
n = n+1;
error(n+1) = abs(x1-x0);
end
end

Iniciar sesión para comentar.

Categorías

Más información sobre Spline Postprocessing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by