You are on page 1of 2

ALGORITMOS RUNGE-KUTTA PARA PVI

Private Sub CommandButton1_Click()


Dim pregunta As Integer
Dim cuadro As Range

pregunta = MsgBox("¿Deseas ingresar los datos?", vbYesNo, "Pregunta")


If pregunta = vbYes Then
Set cuadro = Range("A1:B3")
With cuadro
.Borders.LineStyle = xlContinuous
.Borders.Color = vbRed
.Range("A1").Value = "Datos:"
.Range("A2").Value = "x0 ="
.Range("A3").Value = "Tol ="
.Range("A1:B1").Interior.Color = vbYellow
.Range("B2").Select
End With

Else

End If

End Sub

Private Sub CommandButton2_Click()

Dim n As Integer
Dim x0 As Double
Dim x1 As Double
Dim tol As Double
Dim errorabs As Double

If WorksheetFunction.Count(Range("B2:B3")) = 0 Then
MsgBox "Faltan datos"
Range("B2").Select

Else
x0 = Range("B2").Value
tol = Range("B3").Value

n = 1
Do
x1 = g(x0)
errorabs = Abs(x1 - x0)
x0 = x1
Cells(n, 4) = n
Cells(n, 5) = x1

Página 1 Adolfo Canahuire Condori


ALGORITMOS RUNGE-KUTTA PARA PVI
n = n + 1
Loop While errorabs > tol

End If

End Sub

Private Sub CommandButton3_Click()


ActiveSheet.Cells.Clear
ActiveSheet.Cells.ClearFormats
End Sub

Function g(x)
g = x - 0.25 * (WorksheetFunction.Asin(x) - WorksheetFunction.Pi * x ^ 2
+ 1)
End Function

Página 2 Adolfo Canahuire Condori

You might also like