Reputation: 31
I want to multiply 5 matrix ( all are not of same size) in c++, so what i can do? will i have to use loop 5 times or is there any simple method like as in matlab? sizes of matrix are 1st : 1x4 2nd : 4x4 3rd : 4x4 4th : 4x4 5th : 4x1
Upvotes: 0
Views: 346
Reputation: 132984
You could use boost linear algebra library which defines both matrix and vector types and has multiplication with operator *
.
matrix<int> m1(1,4);
matrix<int> m2(4,4);
matrix<int> m3(4,4);
matrix<int> m4(4,1);
//... initialize your matrices here
matrix<int> result = m1*m2*m3*m4;
Upvotes: 2
Reputation: 3694
Alternatively, you can define the *
operator for the type matrix that you defined yourself, so that you could just write a*b*c*d
Upvotes: 1