user2828274
user2828274

Reputation: 31

multiplication of 5 different size matrix in c ++

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

Answers (2)

Armen Tsirunyan
Armen Tsirunyan

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

Bernhard
Bernhard

Reputation: 3694

  1. Write a function that performs the matrix multiplication for matrices of arbitrary size (with a sanity check).
  2. Use the function four times, once for each multiplication.

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

Related Questions