Bluebit Software
Bluebit Software Support Forum
 Home          Members     Calendar     Who's On

Welcome Guest ( Login | Register )
        



Wrapping methods of MaXC together Expand / Collapse
Message
Posted Tuesday, April 05, 2005 12:04 PM Post #54
 

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie
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 Post #209
 

Bluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit Support
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

Bluebit Software

« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Trifon

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 3:22am

Powered by InstantForum.NET v4.1.4 © 2012
Execution: 0.250. 11 queries. Compression Disabled.
.NET Matrix Library