I am having a hard time understanding how matrix works.
Show older comments
a = [ 1 0; 2 1] ;
b= [ -1 2 ; 0 1] ;
n= a*b
N= a.*b
what is the mathematical differnce between a.*b and a*b.
Answers (3)
.* is the elementwise multiplication, while * is the matrix multiplication:
[a,b; c,d] .* [e,f; g,h] =
[a*e, b*f; c*g, d*h]
[a,b; c,d] * [e,f; g,h] = % [EDITED, typos fixed]
[a*e + b*g, a*f + b*h; c*e + d*g, c*f + d*h]
7 Comments
Caleb Banga
on 25 Feb 2022
Les Beckham
on 25 Feb 2022
@Jan - I think that you mean * instead of .* in your second example, right?
Caleb Banga
on 25 Feb 2022
Corrected matrix multiplication formula:
[a,b; c,d] * [e,f; g,h] =
[a*e + b*g, a*f + b*h; c*e + d*g, c*f + d*h]
% ^ ^
Lets try both of them using the symbolic toolbox:
syms a b c d e f g h
[a,b; c,d] .* [e,f; g,h]
[a,b; c,d] * [e,f; g,h]
Jan
on 26 Feb 2022
@Stephen: Thanks! I've tried to do it manually instead of letting Matlab do this with syms. I do not have the symbolic toolbox and it is beyond my understanding of fair use, that I can simply run it in the forum's online version.
I'm impressed, that you have checked this pile of characters, which are looking like small flies if you are looking from a distance of about 5 meters.
Walter Roberson
on 26 Feb 2022
Edited: Walter Roberson
on 26 Feb 2022
Jan, if the forum will run symbolic toolbox code for you then you are authorized to use the toolbox within the context of the forum; it is a service being provided by Mathworks.
It has the usual 55 second limit, and only about 5 gigabytes of ram, is about half the speed of your desktop, debugger and interactive input is disabled...
Stephen23
on 26 Feb 2022
@Jan: my pleasure! I also spent ten minutes trying to catch those flies, going through the steps of multiplying: however I am slow and those tiny flies are hard to catch. It was only when I was about to post the comment that it occured to me to try the symbolic toolbox, which luckily gave the same result :)
Walter Roberson
on 22 Feb 2022
0 votes
The operator .* is element-by-element multiplication. N = a.*b means that N(J,K) = a(J,K) times b(J,K) with no other elements of a or b influencing the outcome.
The operator * is algebraic matrix multiplication, also known as "inner product". n = a*b means that n(J,K) = dot(a(J,:), b(:,K)) which is an operation that involves a complete row of one matrix and a complete column of the other matrix. Carefully chosen matrix multiplication can express rotation, translation, and scale
Arthur Reis
on 22 Feb 2022
Edited: Arthur Reis
on 22 Feb 2022
0 votes
'*' is the matrix multiplication as is usual in Linear Algebra
'.*' is element-wise multiplication. Each element is multiplied by its correspondent
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!