Posted Monday, January 17, 2005 1:54 PM
|
|
|
|
Dear Trifon,
I have got square of a matrix and I want to calculate the matrix. In other words I need to know how can I calculate A while I have A * A ?
thanks.
|
|
Posted Monday, January 17, 2005 3:46 PM
|
|
|
|
Hi Reza
If Matrix A is a NxN square matrix then it can be written as
A = U * D * Ui
where:
D = A diagonal NxN square matrix containing is its main diagonal the eigenvalues of matrix A
U = The matrix containing the eigenvectors of matrix A.
Ui = The inverse of U.
It is easily understood that
A^2 = (U * D * Ui)^2 = (U * D * Ui) * (U * D *Ui) =
= (U * D) * (Ui * U) * (D * Ui)
but since the middle term (Ui * U) equals unity matrix then
A^2 = (U * D) * (D* Ui)
A^2 = U * (D * D) * Ui
A^2 = U * (D^2) * Ui
Generally A^n = U * (D^n) * Ui
Since matrix D is diagonal in order to find the n power of it we need to only to replace its diagonal elements by their n-th power.
So in order to find the square root of a N x N matrix A:
Use the EigenC method to find both eigenvalues and eigenvectors of the matrix. If your matrix is symmetric then it will have only real eigenvalues you can use the Eigen method and get only the real parts.
Matrix U will be the eigenvectors
Use Inverse method to find Ui
Create matrix D (size NxN) and put in its diagonal the square roots of the eigenvalues.
Use Times method to perform matrix multiplication U * D * Ui.
Please review this example:
'create an example Matrix
Dim A As New Matrix
A.Size 5, 5
A.FillRandom
Debug.Print A.GetString
'Now lets find the square root of A
'We will use CMatrix objects since
'the square root of a matrix may not
'be a real matrix
'Matrix U will fold the eigenvectors
Dim U As New CMatrix
'Matrix V will hold the eigenvalues
Dim V As New CMatrix
'Matrix D will hold the square roots of the
'eigenvalues in its main diagonal
Dim D As New CMatrix
A.EigenC V, U
D.Size V.Rows, V.Rows
Dim i As Long
For i = 0 To V.Rows - 1
'Yes! MaXC has a function for finding
'square roots of complex numbers
D(i, i) = CSqr(V(i, 0))
Next
'Now we will construct the square root of A
' and place the result in matrix R
Dim R As CMatrix
Set R = U.Times(D).Times(U.Inverse)
Debug.Print R.GetString
'Verify the result - R x R should be the
'same as matrix A but in complex form
Debug.Print R.Times(R).GetString()
Trifon Triantafillidis | Lead Developer |
|
|
|
|
|