1. Cálculo de la raíz de una ecuación no lineal mediante el Método Numérico de la Bisección
Utilizando macros de VBA de Excel
Ing. Néstor Augusto Oyarce Linares
naoyarcel@gmail.com
2. aBiseccionGrafica - 1
Option Explicit
Sub XY_10_Dic_2020_3()
Dim X As Double, Y As Double, i As Integer, X1 As Double, X0 As Double, XX As Double
Dim Err As Double, YD As Double, j As Integer, gx0 As Double, gx As Double
'Método Numérico de BISECCIóN
'10 de Diciembre de 2020, ejercicio 3
Cells.Clear
Cells(1, 1).Value = " ECUACION : "
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
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
4. bBiseccionCalculo - 1
Option Explicit
Sub Parte2_Biseccion()
Dim Xa As Double, Ya As Double, i As Integer, Xb As Double, Xm As Double, Yb As Double
Dim Error As Double, Ym As Double, j As Integer, X As Double, Y As Double
Cells.Clear
Cells(1, 1).Value = "Método Numérico de la Biseccion"
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
Xm = (Xa + Xb) / 2
Ya = (Xa) ^ (3) + 2 * (Xa) ^ (2) + 10 * Xa - 20
Yb = (Xb) ^ (3) + 2 * (Xb) ^ (2) + 10 * Xb - 20
Ym = (Xm) ^ (3) + 2 * (Xm) ^ (2) + 10 * Xm - 20
If Ya * Ym < 0 Then Xb = Xm Else Xa = Xm
Error = Abs(Xa - Xb)
Cells(j + 3, 2).Value = Xm
Cells(j + 3, 3).Value = Ym
If Error <= 0.000001 Then Exit For
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
5. Método Numérico de la Biseccion
Valor de X Valor de Y Xf Yf Iteraciones
1.35 -0.394625 1.368808746 1.34702E-05 17
1.375 0.130859375
1.3625 -0.132833984
1.36875 -0.00122583
1.371875 0.06475705
1.3703125 0.03175069
1.36953125 0.015258702
1.369140625 0.007015504
1.368945313 0.002894604
1.368847656 0.000834329
1.368798828 -0.000195765
1.368823242 0.000319278
1.368811035 6.17555E-05
1.368804932 -6.70051E-05
1.368807983 -2.62484E-06
1.368809509 2.95653E-05
1.368808746 1.34702E-05