Message Boards Message Boards

GROUPS:

[✓] Compare these to matrix operations?

Posted 5 months ago
563 Views
|
6 Replies
|
1 Total Likes
|

Consider the following code:

Inverse[{{1,-1},{0,1}}]*{{3,1},{0,2}}^2*{{1,-1},{0,1}}
{{1,1},{0,1}}*{{3,1},{0,2}}^2*{{1,-1},{0,1}}

hello i'm a little bit curious, why the two sentences above give me two different answers .. ? ( notice: Inverse[{{1,-1},{0,1}}] = {{1,1},{0,1}} )

Thanks

6 Replies

Multiplication of matrices need Dot:

Inverse[{{1, -1}, {0, 1}}].{{3, 1}, {0, 2}}.{{3, 1}, {0, 2}}.{{1, -1}, {0, 1}}
{{1, 1}, {0, 1}}.{{3, 1}, {0, 2}}.{{3, 1}, {0, 2}}.{{1, -1}, {0, 1}}

And matrix^2 doesn't give matrix . matrix

Here you must use MatrixPower

Inverse[{{1, -1}, {0, 1}}].MatrixPower[{{3, 1}, {0, 2}}, 2].{{1, -1}, {0, 1}}

{{1, 1}, {0, 1}}.MatrixPower[{{3, 1}, {0, 2}}, 2].{{1, -1}, {0, 1}}

Look at

{{a, b}, {c, d}}^2
MatrixPower[{{a, b}, {c, d}}, 2]
Posted 5 months ago

Hello... Thank you...

But in this way ... how can i calculate the result with matrix point multiplication which works on an element by element basis ?

for example .. A={{1,1},{0,1}}, and i wana get B={{1^2,1^2},{0,1^2}} , or maybe C={{1^3,1^3},{0,1^3}} ... and another example, A={{1,2},{3,4}}, B={{5,6},{7,8}}, and how can i get A.*B={{5,12},{21,32}} ...

In addition ... why can i use the following line and get the correct answer ...? ( Here i didn't use the point . to make multiplication. )

{{1,1},{0,1}}*{{3,1},{0,2}}^2*{{1,-1},{0,1}}

Plus, Times and Power have the Attribute Listable. That means they operate on the elements of a list (or matrix). So your last example is obtained by

a = {{1, 2}, {3, 4}};
b = {{5, 6}, {7, 8}};
a*b

Out[9]= {{5, 12}, {21, 32}}

But your

In[10]:= {{1, 1}, {0, 1}} * {{3, 1}, {0, 2}}^2 * {{1, -1}, {0, 1}}

Out[10]= {{9, -1}, {0, 4}}

is different fron the correct result

In[11]:= {{1, 1}, {0, 1}}.MatrixPower[{{3, 1}, {0, 2}}, 2].{{1, -1}, {0, 1}}

Out[11]= {{9, 0}, {0, 4}}

And even if you meant to square the elements of the inner matrix the result is still different. So you should well define what you really want to do.

In[14]:= {{1, 1}, {0, 1}}.({{3, 1}, {0, 2}}^2 ) .{{1, -1}, {0, 1}}

Out[14]= {{9, -4}, {0, 4}}
Posted 5 months ago

Thanks a lot.

Posted 5 months ago

I mean, in Matlab we can just easily use * and .* to make matrix multiplication and element multiplication..

like ..

a=[1,2;3,4];
b=[5,6;7,8];

a*b
a.*b

ans =

19    22
43    50

ans =

 5    12
21    32

And here it makes it...

As it happens, one can similarly use * and . in the Wolfram Language to do Hadamard and ordinary matrix multiplication respectively.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract