Posted Monday, November 20, 2006 11:43 PM
|
|
|
|
hi, i wish to know that how can i use this Matrix ActiveX Component to calculate the SVD of a matrix? after i made a reference to it, i don't know how to use it in my code. i will be appreciate if you can explain to me as i'm just started to learn VB...
Thank you
|
|
Posted Tuesday, November 21, 2006 12:40 AM
|
|
|
|
Hello,
Have you seen the example code in the documentation? You will need to use the SVD method. I am copying here the example
Private Sub MatrixSVD()
Dim A As New Matrix, U As New Matrix, S As New Matrix, V As New Matrix
Dim B As New Matrix, X As Matrix
Dim i As Long
A.Size 6, 3
A(0, 0) = 6: A(0, 1) = 4: A(0, 2) = 3
A(1, 0) = 2: A(1, 1) = 3: A(1, 2) = 7
A(2, 0) = 1: A(2, 1) = 7: A(2, 2) = 2
A(3, 0) = 6: A(3, 1) = 1: A(3, 2) = 4
A(4, 0) = 8: A(4, 1) = 7: A(4, 2) = 3
A(5, 0) = 3: A(5, 1) = 2: A(5, 2) = 9
B.Size 6, 1
B(0, 0) = 55
B(1, 0) = 37
B(2, 0) = 40
B(3, 0) = 33
B(4, 0) = 60
B(5, 0) = 75
Debug.Print "Over determined set of equations"
Debug.Print "================================"
For i = 0 To 5
Debug.Print " " & A(i, 0) & "*x + " & A(i, 1) _
& "*y + " & A(i, 2) & "*z = " & B(i, 0)
Next
Debug.Print "================================"
A.SVD U, S, V
'Matrix S is diagonal - to form its inverse we need only
'find the reciprocals of its diagonal elements
For i = 0 To 2
'in real code you will need to check
'for zero values here
S(i, i) = 1 / S(i, i)
Next
Set X = V.Times(S).Times(U.Transpose).Times(B)
Debug.Print "Least square fit solution"
Debug.Print "x ="; X(0, 0)
Debug.Print "y ="; X(1, 0)
Debug.Print "z ="; X(2, 0)
End Sub
Trifon Triantafillidis | Lead Developer |
|
|
|
Posted Friday, November 24, 2006 1:55 AM
|
|
|
|
thanks, i kind of know how to use it already.
by the way, is it possible to apply any array to it?
for example:
A(N,m).SVD U, S, V
it seems don't work for me....
thanks
|
|
Posted Friday, November 24, 2006 2:09 AM
|
|
|
|
You will have to create a Matrix Object of equal size, then pass the values of the array to Matrix object using AsArray property and then perform SVD on the Matrix onject.
Trifon Triantafillidis | Lead Developer |
|
|
|
Posted Sunday, November 26, 2006 9:12 PM
|
|
|
|
hi Trifon,
Sorry for troubling you, would you mind to give me some example code of the method which you explained in previous reply? It would be a great help me as i'm stil new in VB... Thanks a lot...
|
|
Posted Tuesday, November 28, 2006 7:51 PM
|
|
|
|
Hi Trifon,
Is it you mean like this?
Sub Build_Matrix()
Global Const MAX_DIM = 6
Global System_DIM As Integer 'Current Matrix [A] dimensions
Global Matrix_A(1 To MAX_DIM, 1 To MAX_DIM)
Dim A() As Double
'Build Matrix_A
A.Size System_DIM, 6
For N = 1 To System_DIM
For m = 1 To 6
Matrix_A(N, m) = Val(Text1(m - 1 + (N - 1) * 6))
Matrix_A(N, m).AsArray = A
Next m
Next N
End Sub
But it don't seem works for me, it prompt "invalid qualifier" at A.size System_DIM, 6
So how can i create a matrix object with size and pass the values of the array to it?
|
|
|
|