El método de la falsa posición o método de interpolación lineal aproxima la raíz de la función mediante una interpolación lineal del intervalo que contiene la raíz verdadera.
grafico
Interpolando los puntos \( (x_{inferior}, f(x_{inferior})) \) y \( (x_{superior}, f(x_{superior})) \) $$ \begin{equation*} \frac{f(x_{superior}) - f(x_{inferior})}{x_{superior} - x_{inferior}} = \frac{f(x_{superior}) - y}{x_{superior} - x} \end{equation*} $$
Según el gráfico \( y = 0 \) y \( x \approx x_{raiz} \) $$ \begin{equation*} \frac{f(x_{superior}) - f(x_{inferior})}{x_{superior} - x_{inferior}} = \frac{f(x_{superior})}{x_{superior} - x_{raiz}} \end{equation*} $$
Despejando \( x_{raiz} \) $$ \begin{equation} x_{raiz} = x_{superior} - \frac{x_{superior} - x_{inferior}}{f(x_{superior}) - f(x_{inferior})} f(x_{superior}) \tag{2} \end{equation} $$
Algoritmo
la raiz verdadera está en el intervalo [x_inferior, x_superior]
calcular x_raiz
si f(x_inferior)*f(x_raiz) < 0
la raiz verdadera está en el intervalo [x_inferior, x_raiz]
calcular x_raiz
si f(x_inferior)*f(x_raiz) > 0
la raiz verdadera está en el intervalo [x_raiz, x_superior]
calcular x_raiz
si f(x_inferior)*f(x_raiz) = 0
se encontró la raiz verdadera
Encontrar la raiz de $$ \begin{equation*} y = x^{3} + 4 x^{2} - 10 \end{equation*} $$
la raíz posiblemente se encuentre en \( [x_{l}, x_{u}] = [1,2] \)
Iteración 0
Intervalo actual $$ \begin{equation*} [x_{l_{0}}, x_{u_{0}}] = [1, 2] \end{equation*} $$
Ordenadas en el intervalo actual $$ \begin{align*} f(x_{l_{0}}) &= f(1) = -5 \\ f(x_{u_{0}}) &= f(2) = 14 \end{align*} $$
Raíz aproximada $$ \begin{equation*} x_{r_{0}} = x_{u_{0}} - \frac{x_{u_{0}} - x_{l_{0}}}{f(x_{u_{0}}) - f(x_{l_{0}})} f(x_{u_{0}}) = 2 - \frac{2 - 1}{14 - (-5)} 14 = 1.263158 \end{equation*} $$
Siguiente intervalo $$ \begin{equation*} [x_{l_{1}}, x_{u_{1}}] = \left \{ \begin{array}{llcll} si & f(x_{l_{0}}) \cdot f(x_{r_{0}}) = f(1) \cdot f(1.263158) < 0 & \longrightarrow & [x_{l_{0}}, x_{r_{0}}] = [1, 1.263158] & \\ si & f(x_{l_{0}}) \cdot f(x_{r_{0}}) = f(1) \cdot f(1.263158) > 0 & \longrightarrow & [x_{r_{0}}, x_{u_{0}}] = [1.263158, 2] & \checkmark \end{array} \right . \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = ? \end{equation*} $$
Iteración 1
Intervalo actual $$ \begin{equation*} [x_{l_{1}}, x_{u_{1}}] = [1.263158, 2] \end{equation*} $$
Ordenadas en el intervalo actual $$ \begin{align*} f(x_{l_{1}}) &= f(1.263158) = -1.602273 \\ f(x_{u_{1}}) &= f(2) = 14 \end{align*} $$
Raíz aproximada $$ \begin{equation*} x_{r_{1}} = x_{u_{1}} - \frac{x_{u_{1}} - x_{l_{1}}}{f(x_{u_{1}}) - f(x_{l_{1}})} f(x_{u_{1}}) = 2 - \frac{2 - 1.263158}{14 - (-1.602273)} 14 = 1.338828 \end{equation*} $$
Siguiente intervalo $$ \begin{equation*} [x_{l_{2}}, x_{u_{2}}] = \left \{ \begin{array}{llcll} si & f(x_{l_{1}}) \cdot f(x_{r_{1}}) = f(1.263158) \cdot f(1.338828) < 0 & \longrightarrow & [x_{l_{1}}, x_{r_{1}}] = [1.263158, 1.338828] & \\ si & f(x_{l_{1}}) \cdot f(x_{r_{1}}) = f(1.263158) \cdot f(1.338828) > 0 & \longrightarrow & [x_{r_{1}}, x_{u_{1}}] = [1.338828, 2] & \checkmark \end{array} \right . \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = \bigg|\frac{x_{r_{1}} - x_{r_{0}}}{x_{r_{1}}}\bigg| \times 100\% = \bigg|\frac{1.338828 - 1.263158}{1.338828}\bigg| \times 100\% = 5.65\% \end{equation*} $$
Iteración 2
Intervalo actual $$ \begin{equation*} [x_{l_{2}}, x_{u_{2}}] = [1.338828, 2] \end{equation*} $$
Ordenadas en el intervalo actual $$ \begin{align*} f(x_{l_{2}}) &= f(1.338828) = -0.430362 \\ f(x_{u_{2}}) &= f(2) = 14 \end{align*} $$
Raíz aproximada $$ \begin{equation*} x_{r_{2}} = x_{u_{2}} - \frac{x_{u_{2}} - x_{l_{2}}}{f(x_{u_{2}}) - f(x_{l_{2}})} f(x_{u_{2}}) = 2 - \frac{2 - 1.338828}{14 - (-0.430362)} 14 = 1.358546 \end{equation*} $$
Siguiente intervalo $$ \begin{equation*} [x_{l_{3}}, x_{u_{3}}] = \left \{ \begin{array}{llcll} si & f(x_{l_{2}}) \cdot f(x_{r_{2}}) = f(1.338828) \cdot f(1.358546) < 0 & \longrightarrow & [x_{l_{2}}, x_{r_{2}}] = [1.263158, 1.338828] & \\ si & f(x_{l_{2}}) \cdot f(x_{r_{2}}) = f(1.338828) \cdot f(1.358546) > 0 & \longrightarrow & [x_{r_{2}}, x_{u_{2}}] = [1.358546, 2] & \checkmark \end{array} \right . \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = \bigg|\frac{x_{r_{2}} - x_{r_{1}}}{x_{r_{2}}}\bigg| \times 100\% = \bigg|\frac{1.358546 - 1.338828}{1.358546}\bigg| \times 100\% = 1.45\% \end{equation*} $$
Iteración 3
Intervalo actual $$ \begin{equation*} [x_{l_{3}}, x_{u_{3}}] = [1.358546, 2] \end{equation*} $$
Ordenadas en el intervalo actual $$ \begin{align*} f(x_{l_{3}}) &= f(1.358546) = -0.110014 \\ f(x_{u_{3}}) &= f(2) = 14 \end{align*} $$
Raíz aproximada $$ \begin{equation*} x_{r_{3}} = x_{u_{3}} - \frac{x_{u_{3}} - x_{l_{3}}}{f(x_{u_{3}}) - f(x_{l_{3}})} f(x_{u_{3}}) = 2 - \frac{2 - 1.358546}{14 - (-0.110014)} 14 = 1.363547 \end{equation*} $$
Siguiente intervalo $$ \begin{equation*} [x_{l_{4}}, x_{u_{4}}] = \left \{ \begin{array}{llcll} si & f(x_{l_{3}}) \cdot f(x_{r_{3}}) = f(1.358546) \cdot f(1.363547) < 0 & \longrightarrow & [x_{l_{3}}, x_{r_{3}}] = [1.263158, 1.338828] & \\ si & f(x_{l_{3}}) \cdot f(x_{r_{3}}) = f(1.358546) \cdot f(1.363547) > 0 & \longrightarrow & [x_{r_{3}}, x_{u_{3}}] = [1.363547, 2] & \checkmark \end{array} \right . \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = \bigg|\frac{x_{r_{3}} - x_{r_{2}}}{x_{r_{3}}}\bigg| \times 100\% = \bigg|\frac{1.363547 - 1.358546}{1.363547}\bigg| \times 100\% = 0.37\% \end{equation*} $$
Seudocódigo para calcular la raíz
function raiz(f(x), x_l, x_u)
x_r = x_u - f(x_u)*(x_u - x_l)/f(x_u) - f(x_l)
return x_r
end function
Seudocódigo para determinar el siguiente intervalo
function intervalo_de_raiz(f(x), x_l, x_u)
x_r = raiz(f(x), x_l, x_u)
if f(x_l)*f(x_r) < 0
x_u = x_r
end if
if f(x_l)*f(x_r) > 0
x_l = x_r
end if
return x_l, x_u
end function
def raiz(f, x_l, x_u):
x_r = x_u - (f(x_u)*(x_u - x_l))/(f(x_u) - f(x_l))
return x_r
def intervalo_de_raiz(f, x_l, x_u):
x_r = raiz(f, x_l, x_u)
if f(x_l)*f(x_r) < 0:
x_u = x_r
if f(x_l)*f(x_r) > 0:
x_l = x_r
return x_l, x_u
function falsa_posicion(f(x), x_inferior, x_superior)
x_raiz_actual = raiz(f(x), x_inferior, x_superior)
error_permitido = 0.000001
while(True)
x_raiz_anterior = x_raiz_actual
x_inferior, x_superior = intervalo_de_raiz(f(x), x_inferior, x_superior)
x_raiz_actual = raiz(f(x), x_inferior, x_superior)
if x_raiz_actual != 0
error_relativo = abs((x_raiz_actual - x_raiz_anterior)/x_raiz_actual)*100
end if
if error_relativo < error_permitido
exit
end if
end while
mostrar x_raiz_actual
end function
O también
function falsa_posicion(f(x), x_inferior, x_superior)
x_raiz_actual = raiz(f(x), x_inferior, x_superior)
for 1 to maxima_iteracion do
x_raiz_anterior = x_raiz_actual
x_inferior, x_superior = intervalo_de_raiz(f(x), x_inferior, x_superior)
x_raiz_actual = raiz(f(x), x_inferior, x_superior)
end for
mostrar x_raiz_actual
end function
def falsa_posicion(f, x_inferior, x_superior):
print("{0:2s}\t{1:12s}\t{2:12s}\t{3:12s}\t{4:16s}".format(' i', 'x inferior', 'x superior', 'raiz', 'error relativo %'))
x_raiz_actual = raiz(f, x_inferior, x_superior)
i = 0
print("{0:2d}\t{1:12.10f}\t{2:12.10f}\t{3:12.10f}\t{4:16s}".format(i, x_inferior, x_superior, x_raiz_actual, '????????????????'))
error_permitido = 0.000001
while True:
x_raiz_anterior = x_raiz_actual
x_inferior, x_superior = intervalo_de_raiz(f, x_inferior, x_superior)
x_raiz_actual = raiz(f, x_inferior, x_superior)
if x_raiz_actual != 0:
error_relativo = abs((x_raiz_actual - x_raiz_anterior)/x_raiz_actual)*100
i = i + 1
print("{0:2d}\t{1:12.10f}\t{2:12.10f}\t{3:12.10f}\t{4:16.13f}".format(i, x_inferior, x_superior, x_raiz_actual, error_relativo))
if (error_relativo < error_permitido) or (i>=20):
break
print('\nx =', x_raiz_actual)
Encontrar la raiz de $$ \begin{equation*} y = x^{3} + 4 x^{2} - 10 \end{equation*} $$
la raíz posiblemente se encuentre en el intervalo \( [1,2] \)
def f(x):
y = x**3 + 4*x**2 - 10
return y
intervalo_de_raiz(f, 1, 2)
(1.263157894736842, 2)
intervalo_de_raiz(f, 1.263157894736842, 2)
(1.3388278388278387, 2)
falsa_posicion(f,1,2)
i x inferior x superior raiz error relativo %
0 1.0000000000 2.0000000000 1.2631578947 ????????????????
1 1.2631578947 2.0000000000 1.3388278388 5.6519547843617
2 1.3388278388 2.0000000000 1.3585463418 1.4514413229699
3 1.3585463418 2.0000000000 1.3635474400 0.3667711199808
4 1.3635474400 2.0000000000 1.3648070318 0.0922908334524
5 1.3648070318 2.0000000000 1.3651237179 0.0231983411795
6 1.3651237179 2.0000000000 1.3652033037 0.0058295916812
7 1.3652033037 2.0000000000 1.3652233020 0.0014648389691
8 1.3652233020 2.0000000000 1.3652283270 0.0003680732282
9 1.3652283270 2.0000000000 1.3652295897 0.0000924861530
10 1.3652295897 2.0000000000 1.3652299069 0.0000232390694
11 1.3652299069 2.0000000000 1.3652299867 0.0000058392979
12 1.3652299867 2.0000000000 1.3652300067 0.0000014672445
13 1.3652300067 2.0000000000 1.3652300117 0.0000003686756
x = 1.3652300117249507
Encontrar la raiz de $$ \begin{equation*} y = \sin{10 x} + \cos{3 x} \end{equation*} $$
la raíz posiblemente se encuentre en el intervalo \( [12,16] \)
from math import sin, cos
def g(x):
y = sin(10*x) + cos(3*x)
return y
intervalo_de_raiz(g, 12, 16)
(14.07311572112783, 16)
intervalo_de_raiz(g, 14.07311572112783, 16)
(14.07311572112783, 15.020154586608253)
falsa_posicion(g, 12, 16)
i x inferior x superior raiz error relativo %
0 12.0000000000 16.0000000000 14.0731157211 ????????????????
1 14.0731157211 16.0000000000 15.0201545866 6.3051206298821
2 14.0731157211 15.0201545866 14.8524823238 1.1289174370701
3 14.8524823238 15.0201545866 14.9297677445 0.5176598990459
4 14.8524823238 14.9297677445 14.8676739795 0.4176427664909
5 14.8524823238 14.8676739795 14.8624123068 0.0354025483071
6 14.8524823238 14.8624123068 14.8621618451 0.0016852310272
7 14.8524823238 14.8621618451 14.8621504074 0.0000769583814
8 14.8524823238 14.8621504074 14.8621498861 0.0000035075371
9 14.8524823238 14.8621498861 14.8621498623 0.0000001598490
x = 14.862149862347621
Encontrar la raiz de $$ \begin{equation*} y = \sin{10 x} + \cos{3 x} \end{equation*} $$
la raíz posiblemente se encuentre en el intervalo \( [14,16] \)
falsa_posicion(g,14,16)
i x inferior x superior raiz error relativo %
0 14.0000000000 16.0000000000 15.1593801187 ????????????????
1 15.1593801187 16.0000000000 15.7079833889 3.4925124165717
2 15.1593801187 15.7079833889 15.4015955980 1.9893249957775
3 15.1593801187 15.4015955980 15.2891944143 0.7351674691564
4 15.2891944143 15.4015955980 15.3395857284 0.3285050518179
5 15.3395857284 15.4015955980 15.3451144933 0.0360294798181
6 15.3451144933 15.4015955980 15.3454516924 0.0021973882086
7 15.3454516924 15.4015955980 15.3454706809 0.0001237395760
8 15.3454706809 15.4015955980 15.3454717448 0.0000069331277
9 15.3454717448 15.4015955980 15.3454718044 0.0000003883530
x = 15.345471804383216