SlideShare a Scribd company logo
Cálculo de la raíz de una ecuación no lineal mediante el Método Numérico de la Falsa Posición
Utilizando macros de VBA de Excel
Ing. Néstor Augusto Oyarce Linares
naoyarcel@gmail.com
aFalsaPosicionGrafica - 1
Option Explicit
Sub XY_10_Dic_2020_4()
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 FALSA POSICIÓN
'10 de Diciembre de 2020, ejercicio 4
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 -5.249
1.2 -3.392
1.3 -1.423
1.4 0.664
-6
-5
-4
-3
-2
-1
0
1
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
Series1
Series2
bFalsaPosicionCalculo - 1
Option Explicit
Sub Parte2_Falsa_Posición()
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
'Función de Recurrencia
'c=b-f(b)*(a-b)/(f(a)-f(b))
Cells.Clear
Cells(1, 1).Value = "Método Numérico de la Falsa Posición"
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.35
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
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
Método Numérico de la Falsa Posición
Valor de X Valor de Y Xf Yf Iteraciones
1.368638564 -0.003576541 1.368808108 2.22045E-15 8
1.368806583 -3.21669E-05
1.368808094 -2.89284E-07
1.368808108 -2.60159E-09
1.368808108 -2.33955E-11
1.368808108 -2.08278E-13
1.368808108 -2.66454E-15
1.368808108 2.22045E-15

More Related Content

PDF
0.0. falsa posicion-naol
PDF
0.0. secante modificada
PDF
0.0. biseccion
PDF
0.0. punto fijo
DOC
Final exam mariluz 1
PDF
8th Alg - L8.2--March12
PDF
Exercise #11 notes
0.0. falsa posicion-naol
0.0. secante modificada
0.0. biseccion
0.0. punto fijo
Final exam mariluz 1
8th Alg - L8.2--March12
Exercise #11 notes

What's hot (14)

PDF
Engr 371 final exam december 1997
DOCX
PDF
Pre-Cal 40S Slides April 9, 2008
PDF
Pre-Cal 30S January 16, 2009
PDF
Pc12 sol c03_cp
PPT
Exponential functions
PDF
Numerical Methods and Applied Statistics Paper (RTU VI Semester)
PDF
2.2 homework a
PDF
Am discrete probability distribution part 2
PPTX
Exponential and logarithmic functions
PDF
Logging in JavaScript - Part-5
PPT
Lesson 3 derivative of hyperbolic functions
PDF
Difrentiation
DOCX
Worksheet sine and cosine rule
Engr 371 final exam december 1997
Pre-Cal 40S Slides April 9, 2008
Pre-Cal 30S January 16, 2009
Pc12 sol c03_cp
Exponential functions
Numerical Methods and Applied Statistics Paper (RTU VI Semester)
2.2 homework a
Am discrete probability distribution part 2
Exponential and logarithmic functions
Logging in JavaScript - Part-5
Lesson 3 derivative of hyperbolic functions
Difrentiation
Worksheet sine and cosine rule
Ad

More from Agua SAC (7)

PDF
0.0. steffensen.naol
PDF
0.0. secante naol
PDF
Publi 05.03.2015
PDF
Trapecio tarea 1
PDF
Sistema información geografica y dengue
PDF
Ejercicio amp2 naol
PDF
Ejercicio amp2 naol
0.0. steffensen.naol
0.0. secante naol
Publi 05.03.2015
Trapecio tarea 1
Sistema información geografica y dengue
Ejercicio amp2 naol
Ejercicio amp2 naol
Ad

0.0. newton raphson

  • 1. Cálculo de la raíz de una ecuación no lineal mediante el Método Numérico de la Falsa Posición Utilizando macros de VBA de Excel Ing. Néstor Augusto Oyarce Linares naoyarcel@gmail.com
  • 2. aFalsaPosicionGrafica - 1 Option Explicit Sub XY_10_Dic_2020_4() 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 FALSA POSICIÓN '10 de Diciembre de 2020, ejercicio 4 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
  • 3. ECUACIÓN : ENSAYOS : X^3+2*X^2+10*X-20 X Y 1.1 -5.249 1.2 -3.392 1.3 -1.423 1.4 0.664 -6 -5 -4 -3 -2 -1 0 1 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 Series1 Series2
  • 4. bFalsaPosicionCalculo - 1 Option Explicit Sub Parte2_Falsa_Posición() 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 'Función de Recurrencia 'c=b-f(b)*(a-b)/(f(a)-f(b)) Cells.Clear Cells(1, 1).Value = "Método Numérico de la Falsa Posición" 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.35 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 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 Falsa Posición Valor de X Valor de Y Xf Yf Iteraciones 1.368638564 -0.003576541 1.368808108 2.22045E-15 8 1.368806583 -3.21669E-05 1.368808094 -2.89284E-07 1.368808108 -2.60159E-09 1.368808108 -2.33955E-11 1.368808108 -2.08278E-13 1.368808108 -2.66454E-15 1.368808108 2.22045E-15