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}) \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]$
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*}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*}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*}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
In [1]:
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
In [2]:
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)
In [3]:
def f(x):
y = x**3 + 4*x**2 - 10
return y
In [4]:
intervalo_de_raiz(f, 1, 2)
Out[4]:
In [5]:
intervalo_de_raiz(f, 1.263157894736842, 2)
Out[5]:
In [6]:
falsa_posicion(f,1,2)
In [7]:
from math import sin, cos
def g(x):
y = sin(10*x) + cos(3*x)
return y
In [8]:
intervalo_de_raiz(g, 12, 16)
Out[8]:
In [9]:
intervalo_de_raiz(g, 14.07311572112783, 16)
Out[9]:
In [10]:
falsa_posicion(g, 12, 16)
In [11]:
falsa_posicion(g,14,16)