?? complexmodule.bas
字號:
Attribute VB_Name = "ComplexModule"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 模塊名:ComplexModule.bas
' 功能: 復數(shù)的運算
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 定義復數(shù)類型
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Type Complex
x As Double ' 復數(shù)實部
y As Double ' 復數(shù)虛部
End Type
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 定義常量 PI
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Const PI = 3.14159265358979
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 模塊名:ComplexModule.bas
' 函數(shù)名:CMul
' 功能: 計算復數(shù)的乘法
' 參數(shù): cpxZ1 - Complex型變量
' cpxZ2 - Complex型變量
' 返回值:Complex型,乘積
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CMul(cpxZ1 As Complex, cpxZ2 As Complex) As Complex
CMul.x = cpxZ1.x * cpxZ2.x - cpxZ1.y * cpxZ2.y
CMul.y = cpxZ1.x * cpxZ2.y + cpxZ1.y * cpxZ2.x
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 模塊名:ComplexModule.bas
' 函數(shù)名:CDiv
' 功能: 計算復數(shù)的除法
' 參數(shù): cpxZ1 - Complex型變量,被除復數(shù)
' cpxZ2 - Complex型變量,除數(shù)
' 返回值:Complex型,商
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CDiv(cpxZ1 As Complex, cpxZ2 As Complex) As Complex
' 局部變量
Dim e As Double, f As Double
If Abs(cpxZ2.x) >= Abs(cpxZ2.y) Then
e = cpxZ2.y / cpxZ2.x
f = cpxZ2.x + e * cpxZ2.y
CDiv.x = (cpxZ1.x + cpxZ1.y * e) / f
CDiv.y = (cpxZ1.y - cpxZ1.x * e) / f
Else
e = cpxZ2.x / cpxZ2.y
f = cpxZ2.y + e * cpxZ2.x
CDiv.x = (cpxZ1.x * e + cpxZ1.y) / f
CDiv.y = (cpxZ1.y * e - cpxZ1.x) / f
End If
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 模塊名:ComplexModule.bas
' 函數(shù)名:CAbs
' 功能: 計算復數(shù)的模
' 參數(shù): cpxZ - Complex型變量,用于求模的復數(shù)
' 返回值:Double型,指定復數(shù)的模
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CAbs(cpxZ As Complex) As Double
'求取實部和虛部的絕對值
cpxZ.x = Abs(cpxZ.x)
cpxZ.y = Abs(cpxZ.y)
' 特殊值處理
If cpxZ.x = 0 Then
CAbs = cpxZ.y
Exit Function
End If
If cpxZ.y = 0 Then
CAbs = cpxZ.x
Exit Function
End If
' 計算模
If cpxZ.x > cpxZ.y Then
CAbs = cpxZ.x * Sqr(1 + (cpxZ.y / cpxZ.x) * (cpxZ.y / cpxZ.x))
Exit Function
End If
CAbs = cpxZ.y * Sqr(1 + (cpxZ.x / cpxZ.y) * (cpxZ.x / cpxZ.y))
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 模塊名:ComplexModule.bas
' 函數(shù)名:CRoot
' 功能: 計算復數(shù)的根
' 參數(shù): cpxZ - Complex型變量,用于求根的復數(shù)
' n - Integer型變量,復數(shù)的根次
' cpxZR - Complex型一維數(shù)組,用于存放求得的復數(shù)的根
' 返回值:Integer型,復數(shù)的根的個數(shù)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CRoot(cpxZ As Complex, n As Integer, cpxZR() As Complex) As Integer
' 局部變量
Dim i As Integer
Dim r As Double
Dim c As Double, c1 As Double, ck As Double, cs As Double
Dim s As Double, s1 As Double, sk As Double, sc As Double
' 特殊值處理
If cpxZ.y = 0 Then
r = Exp(Log(Abs(cpxZ.x)) / n)
cs = 0
Else
If cpxZ.x = 0 Then
r = Exp(Log(Abs(cpxZ.y)) / n)
If cpxZ.y > 0 Then
cs = 1.5707963268
Else
cs = -1.5707963268
End If
Else
r = Exp(Log(cpxZ.x * cpxZ.x + cpxZ.y * cpxZ.y) / n / 2)
cs = Atn(cpxZ.y / cpxZ.x)
End If
End If
If cpxZ.x < 0 Then
cs = cs + PI
End If
' 中間值,用于提高運算速度
cs = cs / n
c = Cos(cs)
s = Sin(cs)
sc = 2 * PI / n
c1 = Cos(sc)
s1 = Sin(sc)
ck = 1
sk = 0
' 第一個根
cpxZR(1).x = c * r
cpxZR(1).y = s * r
' 其余n-1個根
For i = 2 To n
cs = ck * c1 - sk * s1
sc = sk * c1 + ck * s1
' 遞推公式
cpxZR(i).x = (c * cs - s * sc) * r
cpxZR(i).y = (s * cs - c * sc) * r
ck = cs
sk = sc
Next i
' 共有n個根
CRoot = n
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 模塊名:ComplexModule.bas
' 函數(shù)名:CPow
' 功能: 計算復數(shù)的實冪指數(shù)
' 參數(shù): cpxZ - Complex型變量,用于求實冪指數(shù)的復數(shù)
' w - Double型變量,復數(shù)的實冪指數(shù)冪次
' 返回值:Complex型變量,為求得的復數(shù)的實冪指數(shù)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CPow(cpxZ As Complex, w As Double) As Complex
' 局部變量
Dim r As Double, t As Double
' 特殊值處理
If cpxZ.x = 0 And cpxZ.y = 0 Then
CPow.x = 0
CPow.y = 0
Exit Function
End If
' 冪運算公式中的三角函數(shù)運算
If cpxZ.x = 0 Then
If cpxZ.y > 0 Then
t = 1.5707963268
Else
t = -1.5707963268
End If
Else
If cpxZ.x > 0 Then
t = Atn(cpxZ.y / cpxZ.x)
Else
If cpxZ.y >= 0 Then
t = Atn(cpxZ.y / cpxZ.x) + PI
Else
t = Atn(cpxZ.y / cpxZ.x) - PI
End If
End If
End If
' 模的冪
r = Exp(w * Log(Sqr(cpxZ.x * cpxZ.x + cpxZ.y * cpxZ.y)))
' 復數(shù)的實冪指數(shù)
CPow.x = r * Cos(w * t)
CPow.y = r * Sin(w * t)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 模塊名:ComplexModule.bas
' 函數(shù)名:CCPow
' 功能: 計算復數(shù)的復冪指數(shù)
' 參數(shù): cpxZ - Complex型變量,用于求復冪指數(shù)的復數(shù)
' cpxN - Complex型變量,復數(shù)的復冪指數(shù)冪次
' n - Integer型變量,2*PI的整數(shù)倍數(shù)
' 返回值:Complex型變量,為求得的復數(shù)的復冪指數(shù)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CCPow(cpxZ As Complex, cpxN As Complex, n As Integer) As Complex
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -