You are on page 1of 5

Cálculo de la raíz de una ecuación no lineal mediante el Método Numérico de Newton_Raphson

Utilizando macros VBA de Excel

Ing. Néstor Augusto Oyarce Linares

naoyarcel@gmail.com
aNewtonRaphsonGrafica - 1

Option Explicit
Sub X_Y()

Dim X As Double, Y As Double, i As Integer, X1 As Double, X2 As Double


Dim Error As Double, YD As Double, j As Integer

'Método Numérico de Newton-Raphson


'14 de Diciembre de 2020,ejercicio 1

Cells.Clear

Cells(1, 1).Value = " Ecuación : "


Cells(3, 1).Value = " X^3+2*X^2+10*X-20"
Cells(1, 2).Value = " ENSAYOS : "
Cells(3, 2).Value = " X "
Cells(3, 3).Value = " Y "

For i = 1 To 20
X = i - 0.5 * i
Y = (X) ^ (3) + 2 * (X) ^ (2) + 10 * X - 20
Cells(i + 3, 2).Value = X
Cells(i + 3, 3).Value = Y
If Y > 0 Then Exit For
Next i
Cells.EntireColumn.AutoFit
End Sub

Sub Crea_grafico()
Dim grafico As ChartObject
Dim wks As Worksheet
Set wks = ActiveWorkbook.Sheets("Hoja1")
Set grafico = wks.ChartObjects.Add(Left:=400, Width:=450, Top:=50, Height:=200)
grafico.Name = "Grafico_1"
grafico.Chart.ChartType = xlXYScatterSmoothNoMarkers
grafico.Chart.SetSourceData Source:=wks.Range("B4:D15")
End Sub
'Ing. Néstor Augusto Oyarce Linares
Ecuación : ENSAYOS :

4
X^3+2*X^2+10*X-20 X Y
0.5 -14.375 2
1 -7 0
1.5 2.875 -2 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6

-4
Series1
-6
Series2
-8
-10
-12
-14
-16

Se nota que la curva de la ecuación cruza el eje X en el intervalo 1.2 y 1.4 ,para el valor inicial de
iteración con el método de Newton_Raphson de manera aproximada el valor de 1.36
bNewtonRaphsonCalculo - 1

Option Explicit
Sub NewtonRaphson_Calculo()

Dim X1 As Double, X2 As Double, Y As Double, YD As Double, j As Integer


Dim X As Double, Error As Double
'Calculo de la raíz de una ecuación no lineal por el Metodo Numérico De Newton Raphson

Cells.Clear

Cells(1, 2).Value = "Método Numérico de Newton"


Cells(2, 3).Value = "Valor de X"
Cells(2, 4).Value = "Valor de Y"
Cells(2, 7).Value = " Xf "
Cells(2, 8).Value = " Yf "
Cells(2, 9).Value = "Iteraciones"

X1 = 1.36

For j = 1 To 30
Y = (X1) ^ (3) + 2 * (X1) ^ (2) + 10 * X1 - 20
YD = 3 * (X1) ^ 2 + 4 * (X1) + 10
X2 = X1 - Y / YD
Error = Abs(X2 - X1)
X1 = X2
Cells(j + 3, 3).Value = X2
Cells(j + 3, 4).Value = Y
If Error <= 0.0000001 Then Exit For
Next j

X = X2
Cells(4, 7).Value = X
Cells(4, 8).Value = Y
Cells(4, 9).Value = j
Range("G2", "G4").Font.Bold = True
Range("G2", "G4").Font.Color = RGB(8, 44, 196)
Cells.EntireColumn.AutoFit
End Sub
' Ing. Néstor Augusto Oyarce Linares
'Si hubiera alguna observación o inquietud me hacen conocer a mi correo
'naoyarcel@gmail.com
Método Numérico de Newton
Valor de X Valor de Y Xf Yf Iteraciones

1.368830614 -0.185344 1.368808108 3.09318E-09 3


1.368808108 0.000474805
1.368808108 3.09318E-09

You might also like