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 multiply
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Robinou

France
14 Posts

Posted - 10/14/2015 :  11:12:23 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I would like to know if it's possible to multiply an MATRIX by another MATRIX in labtalk language? and if it's not possible how can i do?

Thanks a lot

snowli

USA
1386 Posts

Posted - 10/14/2015 :  2:24:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you have 3 matrix books called MBook1, MBook2 and MBook3, u can run

MBook3=MBook1*MBook2

Thanks, Snow
Go to Top of Page

Robinou

France
14 Posts

Posted - 10/14/2015 :  4:22:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for your quick reply!

It´s working when i have similar dimension between my matrix,

Unfortunaly, i would like to multiply a matrix with 6 columns and 6 rows by another Matrix with 6 rows and 20000 columns.

I use this for the moment :
Range [Mbook] mat1=MSheet1!1, mat2=MSheet2!1, mat3=MSheet3!1;
Mat3=mat2*mat1;

But it does'nt work.

Sorry for this question but i am a beginner in programming.
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 10/14/2015 :  5:59:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Robinou,

When you said multiplication of matrices, are you talking about the cell-to-cell operation; Or, in the sense of "dot product"?
If later, you can try the following script:
///////////////////////
range m1=[MBook1]1!1;
range m2=[MBook2]1!1;
nc1=m1.ncols; nr1=m1.nrows;
nc2=m2.ncols; nr2=m2.nrows;
if(nc1!=nr2) {
  type -a Two matrices are not compatible for dot product;
  return;
}
win -t m; //create output matrix
mbname$=%H;
range m3=[mbname$]1!1;
m3.nrows=nr1;
m3.ncols=nc2;
Loop(ii,1,nr1) {
  Loop(jj,1,nc2) {
    v=0;
    Loop(kk,1,nc1) {v+=(m1[ii,kk]*m2[kk,jj])}
    m3[ii,jj]=v;
  }
}
///////////////////////


For large matrices, this script may be too slow, and you might want to consider faster way such as in Origin C.

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 10/14/2015 6:25:05 PM
Go to Top of Page

Robinou

France
14 Posts

Posted - 10/15/2015 :  06:50:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot Hideo
Go to Top of Page

Robinou

France
14 Posts

Posted - 10/15/2015 :  11:23:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Effectively, my script is too slow and he makes bug.

I must do Origin C,

I make this function :
void matmut ()
{
MatrixPage mp("MATRIXG");
MatrixLayer ml1=mp.Layers(0);
MatrixLayer ml2=mp.Layers(1);
MatrixLayer ml3=mp.Layers(2);
MatrixObject mo1=ml1.MatrixObjects(0);
MatrixObject mo2=ml2.MatrixObjects(0);
MatrixObject mo3=ml3.MatrixObjects(0);

matrix<double> m1=mo1.GetDataObject();
matrix<double> m2=mo2.GetDataObject();
matrix<double>& result=mo3.GetDataObject();
result=m1*m2;
}

but i have an Unknow Error (See my image to see my Matrix

Do you have an idea?

Thanks a lot lot
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 10/20/2015 :  09:35:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Robinou,

Your code works, but you have to create the 3rd sheet in your matrix book before running it (or, add a code to make it if absent).

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 10/20/2015 09:36:53 AM
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