Basic understanding on matlab

2 Ansichten (letzte 30 Tage)
Prabha Kumaresan
Prabha Kumaresan am 20 Dez. 2017
Kommentiert: Walter Roberson am 6 Apr. 2020
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.

Antworten (3)

Walter Roberson
Walter Roberson am 20 Dez. 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.

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

drummer
drummer am 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]

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by