Basic understanding on matlab
1 view (last 30 days)
Show older comments
could anyone tell me what is the difference between array and matrix with example.
if A=[1 2;3 4] and B=[5 6;7 8]
how A*B=[9 12;9 12]
Please explain on it.
0 Comments
Answers (3)
Walter Roberson
on 20 Dec 2017
In MATLAB, every variable is an array. A scalar variable is an array that is 1 by 1. If you had T=[7 6 5 4] then that would be an array of size 1 x 4. Arrays can have multiple dimensions; for example an image might be 1280 x 1024 x 3 .
In MATLAB, arrays that are not empty and are either 1 by something or else something x 1 are also called vectors -- but every vector is also an array.
In MATLAB, arrays that are not empty, and which do not have 3 or more (scalar) dimensions are also called matrix -- but every matrix is also an array, and every vector is also a matrix.
Your case with A=[1 2;3 4] and B=[5 6;7 8], then A*B is algebraic matrix multiplication; see https://en.wikipedia.org/wiki/Matrix_multiplication for that. It is a well-defined mathematical operation between two matrices (that is, involving two 2D arrays), often used in linear algebra.
In MATLAB, the * operator refers to algebraic matrix multiplication unless at least one of the two expressions involved is a scalar (that is, a 1 x 1 array), in which case every element of the other array is multiplied individually by the scalar.
In MATLAB, if you have two arrays the same size and you want to multiply pairs of corresponding elements, then that is the .* operator. Arrays do not need to be 2D to use the .* operator.
0 Comments
drummer
on 5 Apr 2020
How did you get A*B = [9 12; 9 12] ?
with your values for A and B, A*B = [19 22; 43 50] .
Even doing element-wise (A.*B) is = [5 12; 21 32]
See Also
Categories
Find more on Matrix Indexing 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!