0.0.-Total - Secante NAOL

Descargar como pdf o txt
Descargar como pdf o txt
Está en la página 1de 5

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

Utilizando macros de VBA de Excel

Ing. Néstor Augusto Oyarce Linares

[email protected]
aSecanteGrafica - 1

Option Explicit
Sub XY_11_Dic_2020_5()

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

'Método Numérico de LA SECANTE


'14 de Diciembre de 2020, ejercicio 5

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 10
X = 1 + i / 10
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
Range("A1", "A3").Font.Bold = True
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 :

X^3+2*X^2+10*X-20 X Y 1
1.1 -5.249
1.2 -3.392 0
1.3 -1.423 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
-1
1.4 0.664
-2 Series1

-3 Series2

-4

-5

-6
bSecanteCalculo - 1

Option Explicit

Sub Parte2_SECANTE()

Dim Xa As Double, X As Double, Ya As Double, i As Integer, Xb As Double, Xm As Double, Yb As Double


Dim Err As Double, Ym As Double, j As Integer, Y As Double, gx As Double

Cells.Clear

Cells(1, 1).Value = "Método Numérico de la Secante"


Cells(2, 2).Value = "Valor de X"
Cells(2, 3).Value = "Valor de Y"
Cells(2, 5).Value = " Xf "
Cells(2, 6).Value = " Yf "
Cells(2, 7).Value = "Iteraciones"

Xa = 1.3
Xb = 1.4

For j = 1 To 20
Ya = (Xa) ^ (3) + 2 * (Xa) ^ (2) + 10 * Xa - 20
Yb = (Xb) ^ (3) + 2 * (Xb) ^ (2) + 10 * Xb - 20
Xm = Xb - Yb * (Xa - Xb) / (Ya - Yb)
Ym = (Xm) ^ (3) + 2 * (Xm) ^ (2) + 10 * Xm - 20
Err = Abs(Xm - Xb)
Cells(j + 3, 2).Value = Xm
Cells(j + 3, 3).Value = Ym

If Err <= 0.000001 Then Exit For


Xa = Xb
Xb = Xm

Next j

X = Xm
Y = (X) ^ (3) + 2 * (X) ^ (2) + 10 * X - 20
Cells(4, 5).Value = X
Cells(4, 6).Value = Y
Cells(4, 7).Value = j
Range("E1", "E4").Font.Bold = True
Range("E1", "E4").Font.Color = RGB(8, 44, 196)
Cells.EntireColumn.AutoFit
End Sub
' Ing. Néstor Augusto Oyarce Linares
Método Numérico de la Secante
Valor de X Valor de Y Xf Yf Iteraciones

1.368183996 -0.013163968 1.368808108 -3.5083E-14 4


1.368802495 -0.000118417
1.368808109 2.13941E-08
1.368808108 -3.5083E-14

También podría gustarte