SlideShare a Scribd company logo
1 of 5
Download to read offline
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

What's hot

Engr 371 final exam december 1997
Engr 371 final exam december 1997Engr 371 final exam december 1997
Engr 371 final exam december 1997amnesiann
 
Pre-Cal 40S Slides April 9, 2008
Pre-Cal 40S Slides April 9, 2008Pre-Cal 40S Slides April 9, 2008
Pre-Cal 40S Slides April 9, 2008Darren Kuropatwa
 
Pre-Cal 30S January 16, 2009
Pre-Cal 30S January 16, 2009Pre-Cal 30S January 16, 2009
Pre-Cal 30S January 16, 2009Darren Kuropatwa
 
Numerical Methods and Applied Statistics Paper (RTU VI Semester)
Numerical Methods and Applied Statistics Paper (RTU VI Semester)Numerical Methods and Applied Statistics Paper (RTU VI Semester)
Numerical Methods and Applied Statistics Paper (RTU VI Semester)FellowBuddy.com
 
Am discrete probability distribution part 2
Am discrete probability distribution part 2Am discrete probability distribution part 2
Am discrete probability distribution part 2leesongcang
 
Exponential and logarithmic functions
Exponential and logarithmic functionsExponential and logarithmic functions
Exponential and logarithmic functionsNjabulo Nkabinde
 
Lesson 3 derivative of hyperbolic functions
Lesson 3 derivative of hyperbolic functionsLesson 3 derivative of hyperbolic functions
Lesson 3 derivative of hyperbolic functionsLawrence De Vera
 
Difrentiation
DifrentiationDifrentiation
Difrentiationlecturer
 
Worksheet sine and cosine rule
Worksheet  sine and cosine ruleWorksheet  sine and cosine rule
Worksheet sine and cosine ruleMdm ika Sartika
 

What's hot (14)

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

More from Agua SAC

0.0. steffensen.naol
0.0. steffensen.naol0.0. steffensen.naol
0.0. steffensen.naolAgua SAC
 
0.0. secante naol
0.0. secante naol0.0. secante naol
0.0. secante naolAgua SAC
 
Publi 05.03.2015
Publi 05.03.2015Publi 05.03.2015
Publi 05.03.2015Agua SAC
 
Trapecio tarea 1
Trapecio tarea 1Trapecio tarea 1
Trapecio tarea 1Agua SAC
 
Sistema información geografica y dengue
Sistema información geografica y dengueSistema información geografica y dengue
Sistema información geografica y dengueAgua SAC
 
Ejercicio amp2 naol
Ejercicio amp2 naolEjercicio amp2 naol
Ejercicio amp2 naolAgua SAC
 
Ejercicio amp2 naol
Ejercicio amp2 naolEjercicio amp2 naol
Ejercicio amp2 naolAgua SAC
 

More from Agua SAC (7)

0.0. steffensen.naol
0.0. steffensen.naol0.0. steffensen.naol
0.0. steffensen.naol
 
0.0. secante naol
0.0. secante naol0.0. secante naol
0.0. secante naol
 
Publi 05.03.2015
Publi 05.03.2015Publi 05.03.2015
Publi 05.03.2015
 
Trapecio tarea 1
Trapecio tarea 1Trapecio tarea 1
Trapecio tarea 1
 
Sistema información geografica y dengue
Sistema información geografica y dengueSistema información geografica y dengue
Sistema información geografica y dengue
 
Ejercicio amp2 naol
Ejercicio amp2 naolEjercicio amp2 naol
Ejercicio amp2 naol
 
Ejercicio amp2 naol
Ejercicio amp2 naolEjercicio amp2 naol
Ejercicio amp2 naol
 

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