Message Boards Message Boards

[✓] Multiply more than 2 matrices?

GROUPS:

I am trying to find the stiffness matrix of a bilinear rectangular element, so I need to multiply three matrices together in Mathematica. Multiplying three at once didn't seem to work, so then I decided to multiply the first two matrices, and then that result by the third matrix. That doesn't seem to be working, either. It seems that Mathematica is not seeing my [T] matrix as a matrix, but rather just a variable - even after I defined [T] above. Attached is what I've entered.

Any help is greatly appreciated!

Clear [x, y]

Clear [B]

B = ( {
    {(y - 10)/100, 0, (10 - y)/100, 0, y/100, 0, -y/100, 0},
    {0, (x - 10)/100, 0, -x/100, 0, x/100, 0, (10 - x)/100},
    {(x - 10)/100, (y - 10)/100, -x/100, (10 - y)/100, x/100, 
     y/100, (10 - x)/100, -y/100}
   });

Clear [M]

M = ({
    {10666.67, 2666.67, 0},
    {2666.67, 10666.67, 0},
    {0, 0, 4000}
   });

Clear [Q]

Q = Transpose[B].M.B // MatrixForm

Integrate[Q, {x, 0, 10}, {y, 0, 10}]
Attachment

Attachments:
POSTED BY: Tracy Borne
Answer
1 month ago

Check the documentation on MatrixForm. Also it is regarded as good practice to post actual code rather than a picture of code. In case anyone wants to cut-and-paste it for experimenting, say.

POSTED BY: Daniel Lichtblau
Answer
1 month ago

Please post code rather than a picture (and you're likely to get more and better help). Also, it would be good if you could show what didn't seem to work when you multiplied the three matrices.

POSTED BY: Jim Baldwin
Answer
1 month ago

Thank you for your responses. My apologies - I am new here and did try posting the code, but it didn't copy and paste clearly likely because I was trying to show the output as well. I was able to get the matrix multiplication to work, but only after scrapping the entire file and starting over. Now I cannot seem to get a double integration of the resulting matrix to evaluate. The output shows more like a restatement of the problem, and still has variables in the matrix when it should be numerical (they are definite integrals). I am posting the code below, but also attaching a picture so that you can see my results.

Clear [x, y]

Clear [B]

B = ( {
    {(y - 10)/100, 0, (10 - y)/100, 0, y/100, 0, -y/100, 0},
    {0, (x - 10)/100, 0, -x/100, 0, x/100, 0, (10 - x)/100},
    {(x - 10)/100, (y - 10)/100, -x/100, (10 - y)/100, x/100, 
     y/100, (10 - x)/100, -y/100}
   });

Clear [M]

M = ({
    {10666.67, 2666.67, 0},
    {2666.67, 10666.67, 0},
    {0, 0, 4000}
   });

Clear [Q]

Q = Transpose[B].M.B // MatrixForm

Integrate[Q, {x, 0, 10}, {y, 0, 10}]
Attachment

Attachments:
POSTED BY: Tracy Borne
Answer
1 month ago

You can learn the best practices on using forum here: http://wolfr.am/READ-1ST

POSTED BY: Moderation Team
Answer
1 month ago

Try this, and notice each of the subtle changes made to your code,

B = {{(y - 10)/100, 0, (10 - y)/100, 0, y/100, 0, -y/100, 0},
     {0, (x - 10)/100, 0, -x/100, 0, x/100, 0, (10 - x)/100},
     {(x-10)/100, (y-10)/100, -x/100, (10-y)/100, x/100, y/100, (10-x)/100, -y/100}};
M = {{10666.67, 2666.67, 0}, {2666.67, 10666.67, 0}, {0, 0, 4000}};
Q = Transpose[B].M.B;
Integrate[Q, {x, 0, 10}, {y, 0, 10}]

which returns this

{{4888.89, 1666.67, -2888.89, -333.333, -2444.45, -1666.67, 444.445, 333.332},
 {1666.67, 4888.89, 333.332, 444.445, -1666.67, -2444.45, -333.333, -2888.89},
 {-2888.89, 333.332, 4888.89, -1666.67, 444.445, -333.333, -2444.45, 1666.67},
 {-333.333, 444.445, -1666.67, 4888.89, 333.332, -2888.89, 1666.67, -2444.45},
 {-2444.45, -1666.67, 444.445, 333.332, 4888.89, 1666.67, -2888.89, -333.333},
 {-1666.67, -2444.45, -333.333, -2888.89, 1666.67, 4888.89, 333.332, 444.445},
 {444.445, -333.333, -2444.45, 1666.67, -2888.89, 333.332, 4888.89, -1666.67},
 {333.332, -2888.89, 1666.67, -2444.45, -333.333, 444.445, -1666.67, 4888.89}}

Perhaps the documentation wasn't quite clear enough. Applying MatrixForm to an expression does make it perhaps cute to look at, but gives a result which is, roughly, no longer able to be used for any subsequent calculations. If you need cute and and subsequent calculations then you can insert an extra line like this

Print[MatrixForm[Q]];

which will not change the value of Q but will display a formatted result.

And, as with everything in Mathematica, there are always a dozen different ways of accomplishing the same thing. Pick one that you can remember and use without making too many mistakes and stick with it.

POSTED BY: Bill Simpson
Answer
1 month ago

The pitfall is your code Q = Transpose[B].M.B // MatrixForm. When you write this way, the MatrixForm gets recorded inside the definition of Q, and it hampers further evaluation. A workaround is a couple of parentheses:

( Q = Transpose[B].M.B) // MatrixForm

Wolfram would make life easier if they finally found a way to make MatrixForm transparent to calculations.

POSTED BY: Gianluca Gorni
Answer
1 month ago

Bill - thank you so much!! Your suggestion fixed everything - I got exactly the matrix I was hoping to get. I see I was misunderstanding how MatrixForm is recorded and carried forth. I truly appreciate your patient and kind explanation of the problem.

Gianluca - thank you also for your input. I will keep the parentheses in mind, because standard matrix format is more appealing to look at.

POSTED BY: Tracy Borne
Answer
1 month ago

Group Abstract Group Abstract