Basic understanding on matlab

7 次查看(过去 30 天)
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.

回答(3 个)

Walter Roberson
Walter Roberson 2017-12-20
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.

Star Strider
Star Strider 2017-12-20
See the documentation on Array vs. Matrix Operations (link)

drummer
drummer 2020-4-5
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]

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by