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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Matrix Multiplication...am I making this too hard?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

rhrochat

USA
2 Posts

Posted - 12/03/2002 :  6:11:50 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

easwar

USA
1964 Posts

Posted - 12/04/2002 :  11:46:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

greg

USA
1378 Posts

Posted - 12/04/2002 :  3:36:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.

Go to Top of Page

rhrochat

USA
2 Posts

Posted - 12/04/2002 :  7:06:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much...i shall put it to work.
Go to Top of Page

peroma

Germany
26 Posts

Posted - 07/01/2004 :  04:43:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

Mike

USA
357 Posts

Posted - 07/01/2004 :  10:26:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page

peroma

Germany
26 Posts

Posted - 07/01/2004 :  12:21:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000