Posted Tuesday, April 05, 2005 12:04 PM
|
|
|
|
Hello,
I have been wondering if there is a way to wrap together, or nest, several methods of MaXC together, to simplify some work I'm doing. As an example, let's say I have three matrices: matrix W1 is a row vector with 4 elements, matrix A is a 4 x 4 square matrix, and matrix W2 is a column vector with 4 elements. I want to premultiply A by W1 and postmultiply it by W2, with the result then being a single number (call it RESULT).
What I tried first was something like: Set RESULT = W1.Times(A.Times(W2)) This did not work. I found that I had to first create an intermediate result for the portion of the above represented by A.Times(W2), with: Set temp_matrix = A.Times(W2) and then do something like: Set RESULT = W1.Times(temp_matrix) This means that I also had to dimension, instantiate, and size the matrix "temp_matrix", which is three additional lines of code that it would be nice not to have to worry about. Is there some way to nest the functions together?
Thanks!
|
|
Posted Wednesday, April 06, 2005 1:16 PM
|
|
|
|
Did you try this: Set RESULT = W1.Times(A).Times(W2) Also I cannot see why W1.Times(A.Times(W2)) is not working for you.
I have created the following code and all 3 methods return the same result. Please try it in your machine.Private Sub Test()
Dim W1 As Matrix, A As Matrix, W2 As Matrix, RESULT As Matrix
Dim temp_matrix As Matrix
Set W1 = New Matrix
W1.Size 1, 4
W1.FillRandom
Set A = New Matrix
A.Size 4, 4
A.FillRandom
Set W2 = New Matrix
W2.Size 4, 1
W2.FillRandom
' 1st method (suggested)
Set RESULT = W1.Times(A).Times(W2)
Debug.Print RESULT.GetString
' 2nd
Set RESULT = W1.Times(A.Times(W2))
Debug.Print RESULT.GetString
' 3rd
Set temp_matrix = A.Times(W2)
Set RESULT = W1.Times(temp_matrix)
Debug.Print RESULT.GetString
End Sub
I suspect that you have used a variable declaration like this:Dim W1, A As Matrix In the above declaration variable A is declared as Matrix and variable W1 as Variant.
Trifon Triantafillidis | Lead Developer |
|
|
|
|
|