You are on page 1of 1

Sub Sistemas_EDO()

Dim x0, y0, z0, xf, N, h, i, k1, k2, k3, k4, c1, c2, c3, c4 As Double

'Entrada de datos

x0 = Cells(3, 2)
y0 = Cells(4, 2)
z0 = Cells(5, 2)
xf = Cells(6, 2)
N = Cells(7, 2)

'Proceso

h = (xf - x0) / N
i = 1

While i <= N
k1 = fun1(x0, y0, z0)
c1 = fun2(x0, y0, z0)
k2 = fun1(x0 + h / 2, y0 + (h / 2) * k1, z0 + (h / 2) * c1)
c2 = fun2(x0 + h / 2, y0 + (h / 2) * k1, z0 + (h / 2) * c1)
k3 = fun1(x0 + h / 2, y0 + (h / 2) * k2, z0 + (h / 2) * c2)
c3 = fun2(x0 + h / 2, y0 + (h / 2) * k2, z0 + (h / 2) * c2)
k4 = fun1(x0 + h, y0 + h * k3, z0 + h * c3)
c4 = fun2(x0 + h, y0 + h * k3, z0 + h * c3)
y0 = y0 + h * (k1 + 2 * k2 + 2 * k3 + k4) / 6
z0 = z0 + h * (c1 + 2 * c2 + 2 * c3 + c4) / 6
x0 = x0 + h
i = i + 1
Wend

'Resultados
Cells(10, 2) = y0
Cells(11, 2) = z0

End Sub

Function fun1(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double


fun1 = -0.015 * y
End Function

Function fun2(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double


fun2 = 0.015 * y
End Function

You might also like