0% found this document useful (0 votes)
4 views2 pages

Array and Matrix Operations in MATLAB

Uploaded by

keyfi.aldabagh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Array and Matrix Operations in MATLAB

Uploaded by

keyfi.aldabagh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Prepared by: Azheen Taher Abdullah

What is array matrix and how we can use in Matlab give an example with code?

In Matlab, an array is a row or a column, also known as a vector. An index is a positive integer that
identifies the position of a value in the vector.
MATLAB has two different types of arithmetic operations: array operations and matrix operations. You
can use these arithmetic operations to perform numeric computations, for example, adding two numbers,
raising the elements of an array to a given power, or multiplying two matrices.

Array Operations
Array operations execute element by element operations on corresponding elements of vectors, matrices,
and multidimensional arrays. If the operands have the same size, then each element in the first operand
gets matched up with the element in the same location in the second operand. If the operands have
compatible sizes, then each input is implicitly expanded as needed to match the size of the other. For
more information, see Compatible Array Sizes for Basic Operations.
As a simple example, you can add two vectors with the same size.
A = [1 1 1]
A =
1 1 1
B = [1 2 3]
B =
1 2 3
A+B
ans =
2 3 4
Matrix Operations
Matrix operations follow the rules of linear algebra and are not compatible with multidimensional arrays.
The required size and shape of the inputs in relation to one another depends on the operation. For
nonsecular inputs, the matrix operators generally calculate different answers than their array operator
counterparts.
For example, if you use the matrix right division operator, /, to divide two matrices, the matrices must
have the same number of columns. But if you use the matrix multiplication operator, *, to multiply two
matrices, then the matrices must have a common inner dimension. That is, the number of columns in the
first input must be equal to the number of rows in the second input. The matrix multiplication operator
calculates the product of two matrices with the formula,
C(i,j)= ∑ A(i,k)B(k,j).
n k=1
To see this, you can calculate the product of two matrices.
A = [1 3;2 4]
A =

1 3
2 4
B = [3 0;1 5]
B =

3 0
1 5
A*B
ans =

6 15
10 20

You might also like