数値的逆ラプラス変換(複素数計算vba)

Public Type Complex
x As Double
y As Double
End Type

Function ToComplex(x As Double, y As Double) As Complex
ToComplex.x = x
ToComplex.y = y
End Function


Function Cadd(z1 As Complex, z2 As Complex) As Complex
Cadd.x = z1.x + z2.x
Cadd.y = z1.y + z2.y
End Function

Function Csub(z1 As Complex, z2 As Complex) As Complex
Csub.x = z1.x - z2.x
Csub.y = z1.y - z2.y
End Function


Function Cmul(z1 As Complex, z2 As Complex) As Complex
Cmul.x = z1.x * z2.x - z1.y * z2.y
Cmul.y = z1.y * z2.x + z1.x * z2.y
End Function


Function Cdiv(z1 As Complex, z2 As Complex) As Complex
Dim c As Double
c = z2.x * z2.x + z2.y * z2.y
Cdiv.x = (z1.x * z2.x + z1.y * z2.y) / c
Cdiv.y = (z1.y * z2.x - z1.x * z2.y) / c

End Function
Function Conj(z As Complex) As Complex
Conj.x = z.x
comj.y = -z.y
End Function

Function Rez(z As Complex) As Double
Rez = z.x
End Function

Function Imz(z As Complex) As Double
Imz = z.y
End Function

Function Cabs(z As Complex) As Double
Cabs = Sqr(z.x * z.x + z.y * z.y)
End Function

Function atan2(x, y) As Double
Dim pi As Double

pi = 3.14159265358979
If x = 0# And y = 0# Then
atan2 = 0#
Exit Function
End If

If x = 0# Then
If y > 0 Then
atan2 = pi
Exit Function
Else
atan2 = -pi
Exit Function
End If
End If

If x > 0 Then
atan2 = Atn(y / x)
Else
If y > 0 Then
atan2 = pi + Atn(y / x)
Else
atan2 = -pi + Atn(y / x)
End If
End If

End Function

Function Cexp(z As Complex) As Complex
Cexp.x = Exp(z.x) * Cos(z.y)
Cexp.y = Exp(z.x) * Sin(z.y)
End Function

Function Clog(z As Complex) As Complex
Dim R As Double
R = z.x * z.x + z.y * z.y
If R <> 0 Then
Clog.x = 0.5 * Log(R)
Clog.y = atan2(z.x, z.y)
Else
Clog.x = 0#
Clog.y = 0#
End If
End Function

Function Cpow(z1 As Complex, z2 As Complex) As Complex
Cpow = Cexp(Cmul(Clog(z1), z2))
End Function

Function ccosh(z As Complex) As Complex
ccosh.x = (Exp(z.x) * Cos(z.y) + Exp(-z.x) * Cos(-z.y)) / 2
ccosh.y = (Exp(z.x) * Sin(z.y) + Exp(-z.x) * Sin(-z.y)) / 2
End Function

Function csinh(z As Complex) As Complex
csinh.x = (Exp(z.x) * Cos(z.y) - Exp(-z.x) * Cos(-z.y)) / 2
csinh.y = (Exp(z.x) * Sin(z.y) - Exp(-z.x) * Sin(-z.y)) / 2
End Function

Function csqr(z As Complex) As Complex
Dim xx As Double
Dim yy As Double
xx = z.x
yy = z.y
R = Sqr((xx) ^ 2 + (yy) ^ 2)
csqr.x = Sqr(xx + R) / Sqr(2)
csqr.y = Sqr(R - xx) / Sqr(2)
If z.y < 0 Then csqr.y = -csqr.y
End Function

これがないとメインのラプラス変換のプログラムが動かないです。複素数計算のパッケージです。