The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 Matrix Multiplication...am I making this too hard?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
rhrochat Posted - 12/03/2002 : 6:11:50 PM
I know how to define matricies within origin, I understand the setting values screen...but is there any way to simply multiply an mxn matrix by a nxm matrix? Thank you.
6   L A T E S T    R E P L I E S    (Newest First)
peroma Posted - 07/01/2004 : 12:21:44 PM
Hi Mike,

it's magic! I did the same things and this time there were no error measages (which are displayed in English even in the German version) but there was the correct result!

Thank you!!

Peter
Mike Posted - 07/01/2004 : 10:26:32 AM
Hi Peter,

I repeated Greg's procedure step-for-step using both Origin 7 (E) SR0 and SR4, but could not reproduce exactly those error messages. When I switched the order of the matrixes (and matrix2 did not have the same number of columns as matrix1 had rows), I received the following error messages:

Matrix sizes are not compatible.
Failed to open matrix.


Is your GUI in English or was this your translation of the German-language error messages? (It is possible that the German error message does not match the English message word for word.) I can look into this.

Also, please verify that your first matrix has the same number of columns as the second has rows.

Mike
OriginLab

peroma Posted - 07/01/2004 : 04:43:14 AM
Hi,

I am working with Origin 7.0(G) and tried the commands Greg mentioned. But the only meassage I can get is:

Failed to open second matrix.
Failed to open matrix.
#Command Error!

All the definitions were correct and I also checked the order of the matrices in the mat.multiply command.

Thanks for any help

Peter
rhrochat Posted - 12/04/2002 : 7:06:21 PM
Thank you very much...i shall put it to work.
greg Posted - 12/04/2002 : 3:36:46 PM
There is a MULTIPLY method of the MAT object which does matrix multiplication correctly. You have to have three matrices and the two product matrices have to obey the dimension rules for multiplication. The result matrix can be any size and will automatically resize to the correct dimensions.
For example:
Suppose I have a 9 (column) by 7 (row) Matrix1 and a 11 (column) by 9 (row) Matrix2. These fit the rules for multiplication of Matrix1 * Matrix2 (but not the reverse), so I could say:
win -t matrix origin; // Create a new matrix window - 32x32
mat.matname $= %H; // Put name of new matrix into object.property
mat.multiply(matrix1,matrix2); // Multiply
The new matrix will resize to 11 (columns) by 7 (rows) and contain the matrix product.
Note that if the method fails - e.g. if I tried mat.multiply(matrix2,matrix1) above - then an error message types out to the Script Window, but any additional script continues, so you have to provide your own error checking.

easwar Posted - 12/04/2002 : 11:46:47 AM
Hello,

Currently this is not available in the GUI/Menu, and the script command interface does an element-by-element (dot) multiplication than a matrix multiplication.

We will work on adding this to the menu in a future version.

For now, if you have Origin 7, you could compile the following Origin C code and then go to the script window and type:

matmult matrix1 matrix2
or type
matmult matrix1 matrix2 matrix3

The first command will create a new result (product) matrix, whereas the second one puts the result (product) in the third specified matrix.

If you want to make this part of your existing menu, contact tech support.

Easwar
OriginLab.


void matmult(string strMat1, string strMat2, string strMat3="")
{
// Declare mat1, mat2 and check validity
Matrix<double> Mat1(strMat1);
Matrix<double> Mat2(strMat2);
if(!Mat1 || !Mat2)
{
printf("Invalid matix!\n");
return;
}

// Check size compatibility
if(Mat1.GetNumCols() != Mat2.GetNumRows())
{
printf("Incompatible matrix sizes!\n");
return;
}

// If no mat3 specified, create one
if(strMat3.GetLength() == 0)
{
MatrixPage matpg;
matpg.Create("Matrix.otp");
strMat3 = matpg.GetName();
}
// Check validity
Matrix<double> Mat3(strMat3);
if(!Mat3)
{
printf("Invalid matix!\n");
return;
}

// Multiply
Mat3 = Mat1 * Mat2;

}




Edited by - easwar on 12/04/2002 11:49:22 AM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000