The Complex data type defined in Matrix ActiveX Component is used to store and retrieve complex numbers contained in CMatrix objects.
Its definition in Visual Basic would have been like this:
Public Type Complex
Real as Double
Imag as Double
End Type
Note:You should not redefine the above. Once ShortName is being referenced, the
above definition becomes part of your project.
CMatrix objects contain Complex data types. You can access their elements using Complex variables.
'Declaring and sizing a complex matrix Dim CM As CMatrix Set CM = New CMatrix CM.Size 4, 4 'Declaring a Complex variable Dim C As Complex 'Assign C to the complex value (3, -4i) C.Real = 3 C.Imag = -4 'Store this value in the left top most position of the matrix CM.Item(0, 0) = C
The following complex number functions become available to your project in order to assist you in complex number arithmetic.
CAbs(cNumber As Complex) As DoubleReturns the absolute value of a complex number.
CAdd(a As Complex, b As Complex) As Complex
Adds two complex numbers and returns the result.
CDiv(a As Complex, b As Complex) As Complex
Divides a complex number by another and returns the result.
CMul(a As Complex, b As Complex) As Complex
Multiplies two complex numbers.
CSqr(a As Complex) As Complex
Returns the square root of a complex numbers.
CSub(a As Complex, b As Complex) As Complex
Subtracts a complex number from another and returns the result.
The following example demonstrates the use of Complex data type together with the complex arithmetic functions.
'defining Complex variables
Dim C1 As Complex, C2 As Complex
Dim C3 As Complex, C4 As Complex
Dim C5 As Complex, C6 As Complex
Dim C7 As Complex
'Assign C1 variable to the value (2,1i)
C1.Real = 2
C1.Imag = 1
Debug.Print "C1 = ("; CStr(C1.Real); ", "; CStr(C1.Imag); "i)"
'Assign C2 variable to the value (1,3i)
C2.Real = 1
C2.Imag = 3
Debug.Print "C2 = ("; CStr(C2.Real); ", "; CStr(C2.Imag); "i)"
Debug.Print
'C3 = C1 + C2
C3 = CAdd(C1, C2)
Debug.Print "C3 = C1 + C2"
Debug.Print "C3 = ("; CStr(C3.Real); ", "; CStr(C3.Imag); "i)"
Debug.Print
'print the absolute value of C3
Debug.Print "Absolute value of C3 = "; CAbs(C3)
Debug.Print
'C4 = C1 * C2
C4 = CMul(C1, C2)
Debug.Print "C4 = C1 * C2"
Debug.Print "C4 = ("; CStr(C4.Real); ", "; CStr(C4.Imag); "i)"
Debug.Print
'C5 = C4 / C2 = C1
C5 = CDiv(C4, C2)
Debug.Print "C5 = C4 / C2"
Debug.Print "C5 = ("; CStr(C5.Real); ", "; CStr(C5.Imag); "i)"
Debug.Print
'C6 = Square root of C1
C6 = CSqr(C1)
Debug.Print "C6 = Square root of "; "("; CStr(C1.Real); ", "; CStr(C1.Imag); "i)"
Debug.Print "C6 = ("; CStr(C6.Real); ", "; CStr(C6.Imag); "i)"
Debug.Print
' C7 = C6 * C6 = C1
C7 = CMul(C6, C6)
Debug.Print "C7 = C6 * C6 = C1"
Debug.Print "C7 = ("; CStr(C7.Real); ", "; CStr(C7.Imag); "i)"
C1 = (2, 1i) C2 = (1, 3i) C3 = C1 + C2 C3 = (3, 4i) Absolute value of C3 = 5 C4 = C1 * C2 C4 = (-1, 7i) C5 = C4 / C2 C5 = (2, 1i) C6 = Square root of (2, 1i) C6 = (1,45534669022535, 0,343560749722512i) C7 = C6 * C6 = C1 C7 = (2, 1i)