⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complexmodule.bas

📁 清华大学2002年出版的《科学与工程数值计算算法VB》配套源码
💻 BAS
📖 第 1 页 / 共 2 页
字号:
    ' 局部变量
    Dim r As Double, s As Double, u As Double, v As Double
    
     ' 特殊值处理
    If cpxZ.x = 0 Then
        If cpxZ.y = 0 Then
            CCPow.x = 0
            CCPow.y = 0
            Exit Function
        End If
            
        s = 1.5707963268 * (Abs(cpxZ.y) / cpxZ.y + 4 * n)
    Else
        s = 2 * PI * n + Atn(cpxZ.y / cpxZ.x)
        
        If cpxZ.x < 0 Then
            If cpxZ.y > 0 Then
                s = s + PI
            Else
                s = s - PI
            End If
        End If
    End If
    
    ' 求幂运算公式
    r = 0.5 * Log(cpxZ.x * cpxZ.x + cpxZ.y * cpxZ.y)
    v = cpxN.y * r + cpxN.x * s
    u = Exp(cpxN.x * r - cpxN.y * s)
    CCPow.x = u * Cos(v)
    CCPow.y = u * Sin(v)

End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  模块名:ComplexModule.bas
'  函数名:CLn
'  功能:  计算复数的自然对数
'  参数:  cpxZ   - Complex型变量,用于求自然对数的复数
'  返回值:Complex型变量,为求得的复数的自然对数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CLn(cpxZ As Complex) As Complex
    ' 局部变量
    Dim e As Double, f As Double
    
     ' 特殊值处理
    If cpxZ.x = 0 And cpxZ.y = 0 Then
        CLn.x = 0
        CLn.y = 0
        Exit Function
    End If

    ' 根据不同的情况计算复数的自然对数
    If Abs(cpxZ.x) < 1 And Abs(cpxZ.y) < 1 Then
        CLn.x = Abs(cpxZ.x + cpxZ.x) + Abs(cpxZ.y + cpxZ.y)
        CLn.y = 8 * cpxZ.x / CLn.x * cpxZ.x + 8 * cpxZ.y / CLn.x * cpxZ.y
    Else
        e = 0.5 * cpxZ.x
        f = 0.5 * cpxZ.y
        CLn.x = Abs(0.5 * e) + Abs(0.5 * f)
        CLn.y = 0.5 * e / CLn.x * e + 0.5 * f / CLn.x * f
        CLn.x = 0.5 * (Log(CLn.x) + Log(CLn.y)) + 1.03972077084
    End If

    If cpxZ.x <> 0 And Abs(cpxZ.x) >= Abs(cpxZ.y) Then
        If cpxZ.x >= 0 Then
            CLn.y = Atn(cpxZ.y / cpxZ.x)
        Else
            If cpxZ.y >= 0 Then
                CLn.y = Atn(cpxZ.y / cpxZ.x) + PI
            Else
                CLn.y = Atn(cpxZ.y / cpxZ.x) - PI
            End If
        End If
    Else
        CLn.y = -Atn(cpxZ.x / cpxZ.y) + PI / 2 * cpxZ.y / Abs(cpxZ.y)
    End If
    
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  模块名:ComplexModule.bas
'  函数名:CSin
'  功能:  计算复数的正弦
'  参数:  cpxZ   - Complex型变量,用于求正弦的复数
'  返回值:Complex型变量,为求得的复数的正弦
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CSin(cpxZ As Complex) As Complex
    ' 局部变量
    Dim i As Integer
    Dim y1 As Double, br As Double, b1 As Double, b2 As Double
    Dim c(6) As Double
    
    ' 切比雪夫公式的常数系数
    c(1) = 1.13031820798497
    c(2) = 0.04433684984866
    c(3) = 0.00054292631191
    c(4) = 0.00000319843646
    c(5) = 0.00000001103607
    c(6) = 0.00000000002498
    
    y1 = Exp(cpxZ.y)
    CSin.x = 0.5 * (y1 + 1 / y1)
    If Abs(cpxZ.y) >= 1 Then
        CSin.y = 0.5 * (y1 - 1 / y1)
    Else
        b1 = 0
        b2 = 0
        y1 = 2 * (2 * cpxZ.y * cpxZ.y - 1)
        For i = 6 To 1 Step -1
            br = y1 * b1 - b2 - c(i)
            If i <> 1 Then
                b2 = b1
                b1 = br
            End If
        Next i
        
        CSin.y = cpxZ.y * (br - b1)
    End If
    
    ' 组合计算结果
    CSin.x = CSin.x * Sin(cpxZ.x)
    CSin.y = CSin.y * Cos(cpxZ.x)
    
End Function
   
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  模块名:ComplexModule.bas
'  函数名:CCos
'  功能:  计算复数的余弦
'  参数:  cpxZ   - Complex型变量,用于求余弦的复数
'  返回值:Complex型变量,为求得的复数的余弦
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CCos(cpxZ As Complex) As Complex
    ' 局部变量
    Dim i As Integer
    Dim y1 As Double, br As Double, b1 As Double, b2 As Double
    Dim c(6) As Double
    
    ' 切比雪夫公式的常数系数
    c(1) = 1.13031820798497
    c(2) = 0.04433684984866
    c(3) = 0.00054292631191
    c(4) = 0.00000319843646
    c(5) = 0.00000001103607
    c(6) = 0.00000000002498
    
    y1 = Exp(cpxZ.y)
    CCos.x = 0.5 * (y1 + 1 / y1)
    If Abs(cpxZ.y) >= 1 Then
        CCos.y = 0.5 * (y1 - 1 / y1)
    Else
        b1 = 0
        b2 = 0
        y1 = 2 * (2 * cpxZ.y * cpxZ.y - 1)
        For i = 6 To 1 Step -1
            br = y1 * b1 - b2 - c(i)
            If i <> 1 Then
                b2 = b1
                b1 = br
            End If
        Next i
        
        CCos.y = cpxZ.y * (br - b1)
    End If
    
    ' 组合计算结果
    CCos.x = CCos.x * Cos(cpxZ.x)
    CCos.y = -CCos.y * Sin(cpxZ.x)
    
End Function
   
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  模块名:ComplexModule.bas
'  函数名:CTan
'  功能:  计算复数的正切
'  参数:  cpxZ   - Complex型变量,用于求余弦的复数
'  返回值:Complex型变量,为求得的复数的正切
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CTan(cpxZ As Complex) As Complex
    ' 局部变量
    Dim i As Integer
    Dim y1 As Double, br As Double, b1 As Double, b2 As Double
    Dim c(6) As Double
    Dim cpxSin As Complex, cpxCos As Complex
    
    ' 切比雪夫公式的常数系数
    c(1) = 1.13031820798497
    c(2) = 0.04433684984866
    c(3) = 0.00054292631191
    c(4) = 0.00000319843646
    c(5) = 0.00000001103607
    c(6) = 0.00000000002498
    
    y1 = Exp(cpxZ.y)
    CTan.x = 0.5 * (y1 + 1 / y1)
    If Abs(cpxZ.y) >= 1 Then
        CTan.y = 0.5 * (y1 - 1 / y1)
    Else
        b1 = 0
        b2 = 0
        y1 = 2 * (2 * cpxZ.y * cpxZ.y - 1)
        For i = 6 To 1 Step -1
            br = y1 * b1 - b2 - c(i)
            If i <> 1 Then
                b2 = b1
                b1 = br
            End If
        Next i
        
        CTan.y = cpxZ.y * (br - b1)
    End If
    
    ' 组合计算结果
    cpxSin.x = CTan.x * Sin(cpxZ.x)
    cpxSin.y = CTan.y * Cos(cpxZ.x)
    cpxCos.x = CTan.x * Cos(cpxZ.x)
    cpxCos.y = -CTan.y * Sin(cpxZ.x)
    
    CTan = CDiv(cpxSin, cpxCos)
    
End Function
   




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -