Método de la falsa posición modificado

El método de la falsa posición modificado evita que uno de los límites del intervalo permanezca constante.

Si \( f(x_{inferior}) \) permanece constante se usa su promedio

grafico

Interpolando los puntos \( (x_{inferior}, \frac{f(x_{inferior})}{2}) \) y \( (x_{superior}, f(x_{superior})) \) $$ \begin{equation*} \frac{f(x_{superior}) - \frac{f(x_{inferior})}{2}}{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}) - \frac{f(x_{inferior})}{2}}{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}}{2 f(x_{superior}) - f(x_{inferior})} 2 f(x_{superior}) \tag{3} \end{equation} $$

Si \( f(x_{superior}) \) permanece constante se usa su promedio

grafico

Interpolando los puntos \( (x_{inferior}, f(x_{inferior})) \) y \( (x_{superior}, \frac{f(x_{superior})}{2}) \) $$ \begin{equation*} \frac{\frac{f(x_{superior})}{2} - f(x_{inferior})}{x_{superior} - x_{inferior}} = \frac{\frac{f(x_{superior})}{2} - y}{x_{superior} - x} \end{equation*} $$

Según el gráfico \( y = 0 \) y \( x \approx x_{raiz} \) $$ \begin{equation*} \frac{\frac{f(x_{superior})}{2} - f(x_{inferior})}{x_{superior} - x_{inferior}} = \frac{\frac{f(x_{superior})}{2}}{x_{superior} - x_{raiz}} \end{equation*} $$

Despejando \( x_{raiz} \) $$ \begin{equation} x_{raiz} = x_{superior} - \frac{x_{superior} - x_{inferior}}{f(x_{superior}) - 2 f(x_{inferior})} f(x_{superior}) \tag{4} \end{equation} $$

Algoritmo

    la raiz verdadera está en el intervalo [x_inferior, x_superior]
    si f(x_inferior) es constante
        f(x_inferior) = f(x_inferior)/2
    si f(x_superior) es constante
        f(x_superior) = f(x_superior)/2
    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

Ejemplo 1

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}}) &= \left \{ \begin{array}{llcll} si & f(x_{l_{1}}) = f(x_{l_{0}}) & \longrightarrow & \frac{f(x_{l_{1}})}{2} & \\ si & f(x_{l_{1}}) \neq f(x_{l_{0}}) & \longrightarrow & f(x_{l_{1}}) = f(1.263158) = -1.602273 & \checkmark \end{array} \right . \\ f(x_{u_{1}}) &= \left \{ \begin{array}{llcll} si & f(x_{u_{1}}) = f(x_{u_{0}}) & \longrightarrow & \frac{f(x_{u_{1}})}{2} = \frac{f(2)}{2} = 7 & \checkmark \\ si & f(x_{u_{1}}) \neq f(x_{u_{0}}) & \longrightarrow & f(x_{u_{1}}) & \end{array} \right . \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}{7 - (-1.602273)} 7 = 1.400403 \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.400403) < 0 & \longrightarrow & [x_{l_{1}}, x_{r_{1}}] = [1.263158, 1.400403] & \checkmark \\ si & f(x_{l_{1}}) \cdot f(x_{r_{1}}) = f(1.263158) \cdot f(1.400403) > 0 & \longrightarrow & [x_{r_{1}}, x_{u_{1}}] = [1.400403, 2] & \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.400403 - 1.263158}{1.400403}\bigg| \times 100\% = 9.80\% \end{equation*} $$

Iteración 2

Intervalo actual $$ \begin{equation*} [x_{l_{2}}, x_{u_{2}}] = [1.263158, 1.400403] \end{equation*} $$

Ordenadas en el intervalo actual $$ \begin{align*} f(x_{l_{2}}) &= \left \{ \begin{array}{llcll} si & f(x_{l_{2}}) = f(x_{l_{1}}) & \longrightarrow & \frac{f(x_{l_{2}})}{2} = \frac{f(1.263158)}{2} = -0.801137 & \checkmark \\ si & f(x_{l_{2}}) \neq f(x_{l_{1}}) & \longrightarrow & f(x_{l_{2}}) & \end{array} \right . \\ f(x_{u_{2}}) &= \left \{ \begin{array}{llcll} si & f(x_{u_{2}}) = f(x_{u_{1}}) & \longrightarrow & \frac{f(x_{u_{2}})}{2} & \\ si & f(x_{u_{2}}) \neq f(x_{u_{1}}) & \longrightarrow & f(x_{u_{2}}) = f(1.400403) = 0.590885 & \checkmark \end{array} \right . \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}}) = 1.400403 - \frac{1.400403 - 1.263158}{0.590885 - (-0.801137)} 0.590885 = 1.342145 \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.263158) \cdot f(1.342145) < 0 & \longrightarrow & [x_{l_{2}}, x_{r_{2}}] = [1.263158, 1.342145] & \\ si & f(x_{l_{2}}) \cdot f(x_{r_{2}}) = f(1.263158) \cdot f(1.342145) > 0 & \longrightarrow & [x_{r_{2}}, x_{u_{2}}] = [1.342145, 1.400403] & \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.342145 - 1.400403}{1.342145}\bigg| \times 100\% = 4.34\% \end{equation*} $$

Iteración 3

Intervalo actual $$ \begin{equation*} [x_{l_{3}}, x_{u_{3}}] = [1.342145, 1.400403] \end{equation*} $$

Ordenadas en el intervalo actual $$ \begin{align*} f(x_{l_{3}}) &= \left \{ \begin{array}{llcll} si & f(x_{l_{3}}) = f(x_{l_{2}}) & \longrightarrow & \frac{f(x_{l_{3}})}{2} & \\ si & f(x_{l_{3}}) \neq f(x_{l_{2}}) & \longrightarrow & f(x_{l_{3}}) = f(1.342145) = -0.376910 & \checkmark \end{array} \right . \\ f(x_{u_{3}}) &= \left \{ \begin{array}{llcll} si & f(x_{u_{3}}) = f(x_{u_{2}}) & \longrightarrow & \frac{f(x_{u_{3}})}{2} = \frac{f(1.400403)}{2} = 0.295443 & \checkmark \\ si & f(x_{u_{3}}) \neq f(x_{u_{2}}) & \longrightarrow & f(x_{u_{3}}) & \end{array} \right . \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}}) = 1.400403 - \frac{1.400403 - 1.342145}{0.295443 - (-0.376910)} 0.295443 = 1.374803 \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.342145) \cdot f(1.374803) < 0 & \longrightarrow & [x_{l_{3}}, x_{r_{3}}] = [1.342145, 1.374803] & \checkmark \\ si & f(x_{l_{3}}) \cdot f(x_{r_{3}}) = f(1.342145) \cdot f(1.374803) > 0 & \longrightarrow & [x_{r_{3}}, x_{u_{3}}] = [1.374803, 1.400403] & \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.374803 - 1.342145}{1.374803}\bigg| \times 100\% = 2.38\% \end{equation*} $$

Implementación de funciones auxiliares

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 calcular la raíz modificada

function raiz_modificada(x_l, x_u, y_l, y_u)
    x_r = x_u - y_u*(x_u - x_l)/(y_u - y_l)
    return x_r
end function

Seudocódigo para determinar el siguiente intervalo

function intervalo_de_raiz(f(x), x_l, x_u, y_l, y_u)
    x_r = raiz_modificada(x_l, x_u, y_l, y_u)
    if y_l*f(x_r) < 0
        x_u = x_r
    end if
    if y_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 raiz_modificada(x_l, x_u, y_l, y_u):
    x_r = x_u - (y_u*(x_u - x_l))/(y_u - y_l)
    return x_r

def intervalo_de_raiz(f, x_l, x_u, y_l, y_u):
    x_r = raiz_modificada(x_l, x_u, y_l, y_u)
    if y_l*f(x_r) < 0:
        x_u = x_r
    if y_l*f(x_r) > 0:
        x_l = x_r
    return x_l, x_u

Implementación no vectorizada

function falsa_posicion_modificada(f(x), x_inferior, x_superior)
    f_inferior_actual = f(x_inferior)
    f_superior_actual = f(x_superior)
    x_raiz_actual = raiz(f, x_inferior, x_superior)
    error_permitido = 0.000001
    while(True)
        f_inferior_anterior = f_inferior_actual
        f_superior_anterior = f_superior_actual
        x_raiz_anterior = x_raiz_actual
        x_inferior, x_superior = intervalo_de_raiz(f(x), x_inferior, x_superior,f_inferior_actual,f_superior_actual)
        f_inferior_actual = f(x_inferior)
        f_superior_actual = f(x_superior)
        if f_inferior_actual = f_inferior_anterior
            f_inferior_actual = f_inferior_actual/2
        end if
        if f_superior_actual = f_superior_anterior
            f_superior_actual = f_superior_actual/2
        end if
        x_raiz_actual = raiz_modificada(x_inferior, x_superior, f_inferior_actual, f_superior_actual)
        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
    return x_raiz_actual
end function

O tambien

function falsa_posicion_modificada(f(x), x_inferior, x_superior)
    f_inferior_actual = f(x_inferior)
    f_superior_actual = f(x_superior)
    x_raiz_actual = raiz(f, x_inferior, x_superior)
    for i to iteracion_maxima do
        f_inferior_anterior = f_inferior_actual
        f_superior_anterior = f_superior_actual
        x_raiz_anterior = x_raiz_actual
        x_inferior, x_superior = intervalo_de_raiz(f(x), x_inferior, x_superior,f_inferior_actual,f_superior_actual)
        f_inferior_actual = f(x_inferior)
        f_superior_actual = f(x_superior)
        if f_inferior_actual = f_inferior_anterior
            f_inferior_actual = f_inferior_actual/2
        end if
        if f_superior_actual = f_superior_anterior
            f_superior_actual = f_superior_actual/2
        end if
        x_raiz_actual = raiz_modificada(x_inferior, x_superior, f_inferior_actual, f_superior_actual)
    end for
    return x_raiz_actual
end function

def falsa_posicion_modificada(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 %'))
    f_inferior_actual = f(x_inferior)
    f_superior_actual = f(x_superior)
    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:
        f_inferior_anterior = f_inferior_actual
        f_superior_anterior = f_superior_actual
        x_raiz_anterior = x_raiz_actual
        x_inferior, x_superior = intervalo_de_raiz(f, x_inferior, x_superior,f_inferior_actual,f_superior_actual)
        f_inferior_actual = f(x_inferior)
        f_superior_actual = f(x_superior)
        if f_inferior_actual == f_inferior_anterior:
            f_inferior_actual = f_inferior_actual/2
        if f_superior_actual == f_superior_anterior:
            f_superior_actual = f_superior_actual/2
        x_raiz_actual = raiz_modificada(x_inferior, x_superior, f_inferior_actual, f_superior_actual)
        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)

Ejemplo 2

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, f(1), f(2))

(1.263157894736842, 2)

intervalo_de_raiz(f, 1.263157894736842, 2, f(1.263157894736842), f(2))

(1.3388278388278387, 2)

falsa_posicion_modificada(f,1,2)

     i	x inferior  	x superior  	raiz        	error relativo %
     0	1.0000000000	2.0000000000	1.2631578947	????????????????
     1	1.2631578947	2.0000000000	1.4004033693	 9.8004244769837
     2	1.2631578947	1.4004033693	1.3421451337	 4.3406807634509
     3	1.3421451337	1.4004033693	1.3748035389	 2.3754961565948
     4	1.3421451337	1.3748035389	1.3598670256	 1.0983804349468
     5	1.3598670256	1.3748035389	1.3677320256	 0.5750395430186
     6	1.3598670256	1.3677320256	1.3639281150	 0.2788937691733
     7	1.3639281150	1.3677320256	1.3658662134	 0.1418951824503
     8	1.3639281150	1.3658662134	1.3649078080	 0.0702175888990
     9	1.3649078080	1.3658662134	1.3653899706	 0.0353131773282
    10	1.3649078080	1.3653899706	1.3651497210	 0.0175987755998
    11	1.3651497210	1.3653899706	1.3652700739	 0.0088153236502
    12	1.3651497210	1.3652700739	1.3652099600	 0.0044032767682
    13	1.3652099600	1.3652700739	1.3652400339	 0.0022028303181
    14	1.3652099600	1.3652400339	1.3652250015	 0.0011010925722
    15	1.3652250015	1.3652400339	1.3652325189	 0.0005506329830
    16	1.3652250015	1.3652325189	1.3652287605	 0.0002752932901
    17	1.3652287605	1.3652325189	1.3652306398	 0.0001376528251
    18	1.3652287605	1.3652306398	1.3652297002	 0.0000688247723
    19	1.3652297002	1.3652306398	1.3652301700	 0.0000344128200
    20	1.3652297002	1.3652301700	1.3652299351	 0.0000172062956

    x = 1.365229935111884

Ejemplo 3

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, g(12), g(16))

(14.07311572112783, 16)

intervalo_de_raiz(g, 14.730875967228018, 16, f(14.730875967228018), f(16))

(14.730875967228018, 9.855338749311382)

falsa_posicion_modificada(g,12,16)

     i	x inferior  	x superior  	raiz        	error relativo %
     0	12.0000000000	16.0000000000	14.0731157211	????????????????
     1	14.0731157211	16.0000000000	15.3430413313	 8.2768831991868
     2	15.3430413313	16.0000000000	15.3838294244	 0.2651361501958
     3	15.3430413313	15.3838294244	15.3442304026	 0.2580710845741
     4	15.3442304026	15.3838294244	15.3465241851	 0.0149465930303
     5	15.3442304026	15.3465241851	15.3450791246	 0.0094170936996
     6	15.3450791246	15.3465241851	15.3456957430	 0.0040181845808
     7	15.3450791246	15.3456957430	15.3453670176	 0.0021421804087
     8	15.3453670176	15.3456957430	15.3455258885	 0.0010352913206
     9	15.3453670176	15.3455258885	15.3454451841	 0.0005259175826
    10	15.3454451841	15.3455258885	15.3454852202	 0.0002608981458
    11	15.3454451841	15.3454852202	15.3454651262	 0.0001309436678
    12	15.3454651262	15.3454852202	15.3454751547	 0.0000653510882
    13	15.3454651262	15.3454751547	15.3454701360	 0.0000327047421
    14	15.3454701360	15.3454751547	15.3454726442	 0.0000163452876
    15	15.3454701360	15.3454726442	15.3454713898	 0.0000081743570
    16	15.3454713898	15.3454726442	15.3454720170	 0.0000040867642
    17	15.3454713898	15.3454720170	15.3454717034	 0.0000020434821
    18	15.3454717034	15.3454720170	15.3454718602	 0.0000010217170
    19	15.3454717034	15.3454718602	15.3454717818	 0.0000005108643

    x = 15.345471781788051

Ejemplo 4

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_modificada(g,14,16)

     i	x inferior  	x superior  	raiz        	error relativo %
     0	14.0000000000	16.0000000000	15.1593801187	????????????????
     1	15.1593801187	16.0000000000	15.8233005485	 4.1958403542431
     2	15.1593801187	15.8233005485	15.7814368351	 0.2652718750525
     3	15.1593801187	15.7814368351	15.6080622619	 1.1108013940212
     4	15.1593801187	15.6080622619	15.2402895571	 2.4131608744624
     5	15.2402895571	15.6080622619	15.4171836042	 1.1473823730127
     6	15.2402895571	15.4171836042	15.2973205541	 0.7835558498623
     7	15.2973205541	15.4171836042	15.3606259952	 0.4121280020238
     8	15.2973205541	15.3606259952	15.3339065994	 0.1742504142175
     9	15.3339065994	15.3606259952	15.3497433718	 0.1031728805473
    10	15.3339065994	15.3497433718	15.3428954934	 0.0446322430237
    11	15.3428954934	15.3497433718	15.3466184680	 0.0242592502569
    12	15.3428954934	15.3466184680	15.3448587408	 0.0114678615271
    13	15.3448587408	15.3466184680	15.3457666600	 0.0059164147637
    14	15.3448587408	15.3457666600	15.3453211388	 0.0029033030742
    15	15.3453211388	15.3457666600	15.3455462318	 0.0014668295455
    16	15.3453211388	15.3455462318	15.3454343464	 0.0007291122350
    17	15.3454343464	15.3455462318	15.3454904703	 0.0003657356367
    18	15.3454343464	15.3454904703	15.3454624582	 0.0001825433529
    19	15.3454624582	15.3454904703	15.3454764778	 0.0000913596393
    20	15.3454624582	15.3454764778	15.3454694717	 0.0000456560349

    x = 15.345469471650302