# Método de la secante modificada

En el método de la secante modificada se calcula la derivada usando diferenciación numérica

\begin{equation*} f'(x_{i}) \approx \frac{f(x_{i} + \Delta x) - f(x_{i})}{\Delta x} \end{equation*}

se reemplaza en la fórmula del método de Newton-Raphson

$$x_{i+1} = x_{i} - \frac{1}{f'(x_{i})} f(x_{i}) = x_{i} - \frac{\Delta x}{f(x_{i} + \Delta x) - f(x_{i})} f(x_{i})$$

Algoritmo

x_0 es la raiz aproximada actual
x_1 = x_0 - f(x_0)*(deltax)/f(x_0 + deltax) - f(x_0)
x_2 = x_1 - f(x_1)*(deltax)/f(x_1 + deltax) - f(x_1)
x_3 = x_2 - f(x_2)*(deltax)/f(x_2 + deltax) - f(x_2)
...



## Ejemplo 1

Encontrar la raiz de

\begin{equation*} y = x^{5} + x^{3} + 3 \end{equation*}

usar $x = 0$ y $\Delta x = -0.5$ como valores iniciales

### Iteración 0

\begin{equation*} x_{0} = 0 \end{equation*}

Error relativo

\begin{equation*} e_{r} = ? \end{equation*}

### Iteración 1

\begin{equation*} x_{1} = x_{0} - \frac{\Delta x}{f(x_{0} + \Delta x) - f(x_{0})} f(x_{0}) = 0 - \frac{-0.5}{f(-0.5) - f(0)} f(0) = -9.6 \end{equation*}

Error relativo

\begin{equation*} e_{r} = \bigg|\frac{x_{1} - x_{0}}{x_{1}}\bigg| \times 100\% = \bigg|\frac{-9.6 - 0}{-9.6}\bigg| \times 100\% = 100\% \end{equation*}

### Iteración 2

\begin{equation*} x_{2} = x_{1} - \frac{\Delta x}{f(x_{1} + \Delta x) - f(x_{1})} f(x_{1}) = -9.6 - \frac{-0.5}{f(-10.1) - f(-9.6)} f(-9.6) = -7.861884 \end{equation*}

Error relativo

\begin{equation*} e_{r} = \bigg|\frac{x_{2} - x_{1}}{x_{2}}\bigg| \times 100\% = \bigg|\frac{-7.861884 - (-9.6)}{-7.861884}\bigg| \times 100\% = 22.11\% \end{equation*}

### Iteración 3

\begin{equation*} x_{3} = x_{2} - \frac{\Delta x}{f(x_{2} + \Delta x) - f(x_{2})} f(x_{2}) = -7.861884 - \frac{-0.5}{f(-8.361884) - f(-7.861884)} f(-7.861884) = -6.467625 \end{equation*}

Error relativo

\begin{equation*} e_{r} = \bigg|\frac{x_{3} - x_{2}}{x_{3}}\bigg| \times 100\% = \bigg|\frac{-6.467625 - (-7.861884)}{-6.467625}\bigg| \times 100\% = 21.56\% \end{equation*}

## Implementación de funciones auxiliares

function derivada(f(x), x_0, delta_x)
f'(x) = f(x_0 + delta_x) - f(x_0)/delta_x
return f'(x)
end function


Seudocódigo para obtener la raíz

function raiz(f(x), x_0, delta_x):
x_1 = x_0 - f(x_0)/derivada(f(x), x_0, delta_x)
return x_1
end function



In [1]:

pendiente = (f(x_0 + delta_x) - f(x_0))/delta_x
return pendiente

def raiz(f, x_0, delta_x):
x_1 = x_0 - f(x_0)/derivada(f, x_0, delta_x)
return x_1



Seudocódigo

function secante_modificada(f(x), x_0, delta_x)
x_actual = x_0
error_permitido = 0.000001
while(True)
x_anterior = x_actual
x_actual = raiz(f(x), x_anterior, delta_x)
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 secante_modificada(f(x), x_0, delta_x)
x_actual = x_0
for 1 to maxima_iteracion do
x_anterior = x_actual
x_actual = raiz(f(x), x_anterior, delta_x)
end for
mostrar x_actual
end function



In [2]:

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 = raiz(f, x_anterior, delta_x)
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)



## Ejemplo 2

Encontrar la raiz de

\begin{equation*} y = x^{5} + x^{3} + 3 \end{equation*}

usar $x = 0$ y $\Delta x = -0.5$



In [3]:

def f(x):
# f(x) = x^5 + x^3 + 3
y = x**5 + x**3 + 3
return y




In [4]:




Out[4]:

0.3125




In [5]:

raiz(f, 0, -0.5)




Out[5]:

-9.6




In [6]:




i 	 x anterior      	 x actual        	 error relativo %
0 	 ??????????????? 	 0.000000000000000 	 ???????????????
1 	 0.000000000000000 	 -9.600000000000000 	 100.00000000000
2 	 -9.600000000000000 	 -7.861884473794202 	  22.10812855365
3 	 -7.861884473794202 	 -6.467625051576309 	  21.55751780753
4 	 -6.467625051576309 	 -5.347892881165710 	  20.93781972249
5 	 -5.347892881165710 	 -4.447268168383268 	  20.25118968955
6 	 -4.447268168383268 	 -3.721545685895121 	  19.50056626306
7 	 -3.721545685895121 	 -3.135622199326246 	  18.68603579522
8 	 -3.135622199326246 	 -2.661854770239923 	  17.79839510341
9 	 -2.661854770239923 	 -2.278788100410730 	  16.81010488690
10 	 -2.278788100410730 	 -1.970139879918845 	  15.66630997311
11 	 -1.970139879918845 	 -1.723899448763318 	  14.28392075490
12 	 -1.723899448763318 	 -1.531345519287236 	  12.57416612064
13 	 -1.531345519287236 	 -1.385789759997517 	  10.50345178550
14 	 -1.385789759997517 	 -1.281061052240061 	   8.17515352405
15 	 -1.281061052240061 	 -1.210232120622861 	   5.85250799497
16 	 -1.210232120622861 	 -1.165395607310976 	   3.84732128992
17 	 -1.165395607310976 	 -1.138660390067439 	   2.34795356691
18 	 -1.138660390067439 	 -1.123437933829515 	   1.35498862728
19 	 -1.123437933829515 	 -1.115037168447288 	   0.75340675808
20 	 -1.115037168447288 	 -1.110489150566135 	   0.40955086133

x = -1.1104891505661354



## Ejemplo 3

Encontrar la raiz de

\begin{equation*} y = x^{5} + x^{3} + 3 \end{equation*}

usar $x = 0$ y $\Delta x = -1$



In [7]:




i 	 x anterior      	 x actual        	 error relativo %
0 	 ??????????????? 	 0.000000000000000 	 ???????????????
1 	 0.000000000000000 	 -1.500000000000000 	 100.00000000000
2 	 -1.500000000000000 	 -1.422113622480146 	   5.47680412371
3 	 -1.422113622480146 	 -1.358063923532322 	   4.71625067406
4 	 -1.358063923532322 	 -1.305788923041259 	   4.00332699785
5 	 -1.305788923041259 	 -1.263460697485440 	   3.35018142156
6 	 -1.263460697485440 	 -1.229455240991364 	   2.76589625716
7 	 -1.229455240991364 	 -1.202339201763378 	   2.25527365225
8 	 -1.202339201763378 	 -1.180863453314626 	   1.81864790450
9 	 -1.180863453314626 	 -1.163956609232255 	   1.45253216041
10 	 -1.163956609232255 	 -1.150715065452284 	   1.15072307451
11 	 -1.150715065452284 	 -1.140388941972345 	   0.90549137228
12 	 -1.140388941972345 	 -1.132364949103758 	   0.70860484289
13 	 -1.132364949103758 	 -1.126147808477357 	   0.55207145808
14 	 -1.126147808477357 	 -1.121341770889101 	   0.42859703554
15 	 -1.121341770889101 	 -1.117633363508680 	   0.33180893677
16 	 -1.117633363508680 	 -1.114776030199689 	   0.25631456289
17 	 -1.114776030199689 	 -1.112576935863598 	   0.19765773181
18 	 -1.112576935863598 	 -1.110885931416579 	   0.15222124965
19 	 -1.110885931416579 	 -1.109586512696503 	   0.11710837372
20 	 -1.109586512696503 	 -1.108588527715178 	   0.09002302986

x = -1.108588527715178