Basic understanding on matlab

조회 수: 7 (최근 30일)
Prabha Kumaresan
Prabha Kumaresan 2017년 12월 20일
댓글: Walter Roberson 2020년 4월 6일
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