I need to write a program, which shows the different combinations in which matrices can be multiplied.

The output should look like below :
When there are two matrices multiplied there is one combination
(XX)

When there are three matrices multiplied there are two combinations
(X(XX)) ((XX)X)

When there are four matrices multiplied there are five combinations
(X(X(XX))) ((X(XX))X) (X((XX)X)) (((XX)X)X) ((XX)(XX))

Can someone please help me with its logic?
Thank you,

I need to write a program, which shows the different combinations in which matrices can be multiplied.

The output should look like below :
When there are two matrices multiplied there is one combination
(XX)

When there are three matrices multiplied there are two combinations
(X(XX)) ((XX)X)

When there are four matrices multiplied there are five combinations
(X(X(XX))) ((X(XX))X) (X((XX)X)) (((XX)X)X) ((XX)(XX))

Can someone please help me with its logic?
Thank you,

Matrix multiplication is non-commutative operation, so X*Y!=Y*X.
So in your examples-
XY -> 2 combinations XY and YX
XYZ -> respectively 8 combinations.
But maybe it can be that your assignment ignores this fact for the sake of simplicity of assignment.

Matrix multiplication is non-commutative operation, so X*Y!=Y*X.
So in your examples-
XY -> 2 combinations XY and YX
XYZ -> respectively 8 combinations.
But maybe it can be that your assignment ignores this fact for the sake of simplicity of assignment.

As he seems to have only one matrix X that indeed seems to be the case.

This article has been dead for over six months. Start a new discussion instead.