0% found this document useful (0 votes)
48 views

Arithmatic Operatores On Matrix in Matlab

The document summarizes various arithmetic operators for matrices and arrays in MATLAB. It discusses addition, subtraction, multiplication, division, transpose, and exponentiation operations. Matrix operations require the same size matrices, while array operations perform element-wise computations. Matrix multiplication follows rules for linear algebra where the number of columns of the first matrix equals the rows of the second. Examples are provided to demonstrate various operations.

Uploaded by

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

Arithmatic Operatores On Matrix in Matlab

The document summarizes various arithmetic operators for matrices and arrays in MATLAB. It discusses addition, subtraction, multiplication, division, transpose, and exponentiation operations. Matrix operations require the same size matrices, while array operations perform element-wise computations. Matrix multiplication follows rules for linear algebra where the number of columns of the first matrix equals the rows of the second. Examples are provided to demonstrate various operations.

Uploaded by

Zakaria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Arithmetic Operators (matrix and array)

+ addition
- subtraction
* multiplication
/ division
^ power
‘ complex conjugate transpose
 Array arithmetic operations are carried out element by element, and can be used with
multidimensional arrays. The period character (.) distinguishes the array operations from the
matrix operations. However, since the matrix and array operations are the same for addition and
subtraction, the character pairs .+ and .- are not used.

 + Addition, A+B adds A and B. A and B must have the same size, unless one is a scalar. A
scalar can be added to a matrix of any size.

 - Subtraction, A-B subtracts B from A. A and B must have the same size, unless one is a
scalar. A scalar can be subtracted from a matrix of any size.
Example 1
Given A and B:

Addition Subtraction
 For c a scalar and

Example 2
>>c= 5
>>b= A+c
Matrix multiplication
C = A*B is the linear algebraic product of the matrices A and B. More precisely,

For nonscalar A and B, the number of columns of A must equal the number of rows of B.

Transpose
 
Matrix multiplication

Scaler multiplication: suppose A is a 2*3 matrix


 𝐴 ∗ 𝑐= 𝐴 11 ∗𝑐 𝐴 12 ∗ 𝑐 𝐴13 ∗ 𝑐
[𝐴 21 ∗ 𝑐 𝐴 22 ∗ 𝑐 𝐴23 ∗ 𝑐 ]
6
Example: Matrix Multiplication:
  0 5 0 4 6 −2

[ ] [ ]
[ 𝐴 ]= 8 3 7 ,[ 𝐵 ]= 7 2 3 ,
9 −2 9
 Matlab command :
1 3 −4

 >>A=[0 5 0;8 3 7;9 -2 9]’


 >>B=[4 6 -2;7 2 3;1 3 -4]
 >> A*B
 

Note:  A *  B   B *  A
Array multiplication
 .* Array multiplication. A.*B is the element-by-element product of the arrays A and B. A and B must
have the same size, unless one of them is a scalar.

 A11 A12 A13   B11 B12 B13   A11  B11 A12  B12 A13  B13 
 A.   B    A21 A22 A23 .   B21 B22 B23    A21  B21 A22  B22 A23  B23 
 A31 A32 A33   B31 B32 B33   A31  B31 A32  B32 A33  B33 

0 5 0 4 6  2 0  4 5  6 0    2    0 30 0 
 A.   B   8 3 7.  7 2 3   8  7 3  2 7  3   56 6 21 
9  2 9  1 3  4  9 1  2  3 9    4    9  6  36

Matlab command:
>>A=[0 5 0;8 3 7;9 -2 9]’
>> B=[4 6 -2;7 2 3;1 3 -4
>> A.*B
Matrix division
Left division, \:

Left division is one of MATLAB's two


kinds of matrix division
 Used to solve the matrix equation AX=B
 A is a square matrix, X, B are column vectors
 Solution is X = A-1B
 A\B is roughly the same as inv(A)*B

In MATLAB, solve by using left division


operator (\), i.e.,
>> X = A \ B

9
Matrix Division
Right division, /:

Right division is the other kind of


MATLAB’s matrix division
 Used to solve the matrix equation XC=D
 C is a square matrix, X, D are row vectors
 Solution is X = D·C-1
 D/C is roughly the same as D*inv(C)

In MATLAB, solve by using right


division operator (/), i.e.,
>> X = D / C

10
Example: consider the following set of equations, find the solution of the equation:
5x+2y-9z=44
-9x-3y+22=11
6x+7y+32=5
Note: Suppose the determinate of matrix A nonzero
Solution: (using matlab commands)
>>a=[5 2 -9;-9 -3 22;6 7 32]
>>b=[44;11;5]
>>k=a\b
k=

1.0e+03 *

2.4624
-4.1378
0.4436
The result in k represents the values of x,y and z
Array division
 ./ Array right division. A./B is the matrix with elements A(i,j)/B(i,j). A and B must have the same
size, unless one of them is a scalar.
 .\ Array left division. A.\B is the matrix with elements B(i,j)/A(i,j). A and B must have the same
size, unless one of them is a scalar.
Example:

x = A(1,:) y = A(3 ,:) b = x .* y c=x./y d = x .^2


x= Y= b= c= d=
1 2 3 3 4 -1 3 8 -3 0.33 0.5 -3 1 4 9
Exponentiation

 Example1: suppose a2=[1 2 3], write a matlab command to find


Matlab command:
>> a2=[1 2 3]
>> a2.^2 ans= 1 4 9
 Example2: suppose a=[1 2 3] and b=[2 4 6] write a matlab command to find
Matlab command:
>> a=[1 2 3]
>> b=[2 4 6]
>> a.^b
ans =

1 16 729 13
Matrix transpose: A' is the linear algebraic transpose of A

Array transpose. A.' is the array transpose of A


T T
 A11 A12 A13   A11 A21 A31  0 5 0 0 8 9 
 A T   A21 A22 A23    A12 A22 A32   8 3 7   5 3  2
 A31 A32 A33   A13 A23 A33  9  2 9  0 7 9 

Example: suppose that


a=

1 2 3
4 5 6
7 8 9
MATLAB command:
>> a=[1 2 3;4 5 6;7 8 9];
>>a’
ans =
1 4 7 Note: The transpose of any matrix
2 5 8 switches the column with row
3 6 9

You might also like