El método del punto fijo consiste en transformar una función \( f(x) = 0 \) en \( x = g(x) \) y obtener la raíz en forma iterativa $$ \begin{equation} x_{i+1} = g(x_{i}) \tag{5} \end{equation} $$
Algoritmo
x_0 es la raiz aproximada
x_1 = f(x_0)
x_2 = f(x_1)
x_3 = f(x_2)
...
Encontrar la raiz de $$ \begin{equation*} y = e^{-x} - x \end{equation*} $$
Reemplazamos \( y = 0 \) $$ \begin{equation*} 0 = e^{-x} - x \end{equation*} $$
Despejando \( x \) $$ \begin{equation*} x = e^{-x} \end{equation*} $$
Transformando en una función iterativa $$ \begin{equation*} x_{i+1} = e^{-x_{i}} \end{equation*} $$
Iteración 0
Raíz aproximada $$ \begin{equation*} x_{0} = 0 \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = ? \end{equation*} $$
Iteración 1
Raíz aproximada $$ \begin{equation*} x_{1} = e^{-0} = 1 \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = \bigg|\frac{1 - 0}{1}\bigg| \times 100\% = 100\% \end{equation*} $$
Iteración 2
Raíz aproximada $$ \begin{equation*} x_{2} = e^{-1} = 0.367879 \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = \bigg|\frac{0.367879 - 1}{0.367879}\bigg| \times 100\% = 171.83\% \end{equation*} $$
Iteración 3
Raíz aproximada $$ \begin{equation*} x_{3} = e^{-0.367879} = 0.692201 \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = \bigg|\frac{0.692201 - 0.367879}{0.692201}\bigg| \times 100\% = 46.85\% \end{equation*} $$
Seudocódigo
function punto_fijo(f(x), x_0)
x_actual = x_0
error_permitido = 0.000001
while(True)
x_anterior = x_actual
x_actual = f(x_anterior)
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_actual
end function
O también
function punto_fijo(f(x), x_0)
x_actual = x_0
for 1 to maxima_iteracion do
x_anterior = x_actual
x_actual = f(x_anterior)
end for
mostrar x_actual
end function
from math import exp
def f(x):
# f(x) = exp(-x) - x
y = exp(-x)
return y
def punto_fijo(f, x_0):
print("{0:s} \t {1:15s} \t {2:15s} \t {3:15s}".format('i', 'x anterior', 'x actual', 'error relativo %'))
x_actual = x_0
i = 0
print("{0:d} \t {1:15s} \t {2:.15f} \t {3:15s}".format(i, '???????????????', x_actual, '???????????????'))
error_permitido = 0.000001
while True:
x_anterior = x_actual
x_actual = f(x_anterior)
if x_actual != 0:
error_relativo = abs((x_actual - x_anterior)/x_actual)*100
i = i + 1
print("{0:d} \t {1:.15f} \t {2:.15f} \t {3:15.11f}".format(i, x_anterior, x_actual, error_relativo))
if (error_relativo < error_permitido) or (i>=20):
break
print('\nx =', x_actual)
punto_fijo(f, 0)
i x anterior x actual error relativo %
0 ??????????????? 0.000000000000000 ???????????????
1 0.000000000000000 1.000000000000000 100.00000000000
2 1.000000000000000 0.367879441171442 171.82818284590
3 0.367879441171442 0.692200627555346 46.85363946134
4 0.692200627555346 0.500473500563637 38.30914659333
5 0.500473500563637 0.606243535085597 17.44678968115
6 0.606243535085597 0.545395785975027 11.15662252538
7 0.545395785975027 0.579612335503379 5.90335081441
8 0.579612335503379 0.560115461361089 3.48086697962
9 0.560115461361089 0.571143115080177 1.93080393126
10 0.571143115080177 0.564879347391050 1.10886824205
11 0.564879347391050 0.568428725029061 0.62441911918
12 0.568428725029061 0.566414733146883 0.35556841380
13 0.566414733146883 0.567556637328283 0.20119651614
14 0.567556637328283 0.566908911921495 0.11425564022
15 0.566908911921495 0.567276232175570 0.06475156780
16 0.567276232175570 0.567067898390788 0.03673877244
17 0.567067898390788 0.567186050099357 0.02083120848
18 0.567186050099357 0.567119040057215 0.01181586888
19 0.567119040057215 0.567157044001298 0.00670077970
20 0.567157044001298 0.567135490206278 0.00380046662
x = 0.5671354902062784
Encontrar la raiz de $$ \begin{equation*} y = x^{2} - 5 x + 3 \end{equation*} $$
Reemplazamos \( y = 0 \) $$ \begin{equation*} 0 = x^{2} - 5 x + 3 \end{equation*} $$
Despejando \( x \) $$ \begin{equation*} x = -\frac{3}{x - 5} \end{equation*} $$
Transformando en una función iterativa $$ \begin{equation*} x_{i+1} = -\frac{3}{x_{i} - 5} \end{equation*} $$
Iteración 0
Raíz aproximada $$ \begin{equation*} x_{0} = 1.85 \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = ? \end{equation*} $$
Iteración 1
Raíz aproximada $$ \begin{equation*} x_{1} = -\frac{3}{1.85 - 5} = 0.952381 \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = \bigg|\frac{0.952381 - 1.85}{0.952381}\bigg| \times 100\% = 94.25\% \end{equation*} $$
Iteración 2
Raíz aproximada $$ \begin{equation*} x_{2} = -\frac{3}{0.952381 - 5} = 0.741176 \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = \bigg|\frac{0.741176 - 0.952381}{0.741176}\bigg| \times 100\% = 28.50\% \end{equation*} $$
Iteración 3
Raíz aproximada $$ \begin{equation*} x_{3} = -\frac{3}{0.741176 - 5} = 0.704420 \end{equation*} $$
Error relativo $$ \begin{equation*} e_{r} = \bigg|\frac{0.704420 - 0.741176}{0.704420}\bigg| \times 100\% = 5.22\% \end{equation*} $$
def g(x):
# f(x) = x**2 - 5*x + 3
y = -3 / (x - 5)
return y
punto_fijo(g, 1.85)
i x anterior x actual error relativo %
0 ??????????????? 1.850000000000000 ???????????????
1 1.850000000000000 0.952380952380952 94.25000000000
2 0.952380952380952 0.741176470588235 28.49584278156
3 0.741176470588235 0.704419889502762 5.21799307958
4 0.704419889502762 0.698392282958199 0.86306889289
5 0.698392282958199 0.697413664224847 0.14032112985
6 0.697413664224847 0.697255038220987 0.02275006922
7 0.697255038220987 0.697229333053386 0.00368675935
8 0.697229333053386 0.697225167738000 0.00059741323
9 0.697225167738000 0.697224492786874 0.00009680542
10 0.697224492786874 0.697224383417362 0.00001568642
11 0.697224383417362 0.697224365695060 0.00000254184
12 0.697224365695060 0.697224362823327 0.00000041188
x = 0.6972243628233274