matlab 1(operations on_matrix)

14
MATLAB Learning for Beginners This is my first presentation on basic mathematical operations in MATLAB.

Upload: harman-kaur

Post on 16-Apr-2017

48 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Matlab 1(operations on_matrix)

MATLAB Learning for Beginners

This is my first presentation on basic mathematical operations in MATLAB.

Page 2: Matlab 1(operations on_matrix)

Declare a 3x3 matrixAs we can see, declaring a matrix is very simple in MATLAB. It can be done in the form of array, where ‘,(comma)’ is used as column separator and ‘;(semicolon)’ is used as row separtor.In our example, there are three rows and in each row there are three columns.

Page 3: Matlab 1(operations on_matrix)

Addition operationsingle expression used to add common value to each element of matrix.The result is stored in matrix at left of ‘=‘ operator.NOTE: We can store the result in same matrix by keeping the same matrix on lefthand side and right hand side of ‘=‘ operator. Like this: mat=mat+5

Page 4: Matlab 1(operations on_matrix)

Subtraction operationSingle expression is used to subtract each element of matrix with given value.A=A-4 will subtract each element of A with 4 and result is stored in A itself.

Page 5: Matlab 1(operations on_matrix)

Multiplication operationTo multiply each element of matrix we use multiplication expression.A=A*4 ie every element of A is multiplied by 4 and stored back into matrix A.

Page 6: Matlab 1(operations on_matrix)

DIVISION OPERATIONLike other mathematical operations, division is also a single expression task, the result is upto four digits of decimal.A=A/3 , the result of this expression will be each element of A is replaced by quotient after division by 3

Page 7: Matlab 1(operations on_matrix)

Power operationA=A.^n here n is the value of power, this expression will result as ‘each element of matrix A is raised to power n . As in our example we have raised every element of matrix mat to 2 and save the resultant matrix as mat11

Page 8: Matlab 1(operations on_matrix)

ADDITION OF TWO MATRICESADDITION OF TWO OR MORE MATRICES OF SAME ORDER IS PRETTY EASY, EACH ELEMENT AT PARTICULAR POSITION say A11,B11, if there are two matrices A,B. are added and result is stored in resultant matrix which is on left of ‘=‘ operator.NOTE: we can add matrices only if they have same order(number of rows and columns)

Page 9: Matlab 1(operations on_matrix)

Addition of matrices NOT having same orderAS WE CAN SEE IN THE SCREEENSHOT, THIS IS THE ERROR MESSAGE WE GET, WHEN WE TRY TO ADD TWO OR MORE MATRICES , WHICH ARE OF DIFFERENT ORDER.

Page 10: Matlab 1(operations on_matrix)

Subtraction of two or more matricesNOTE: DIMENSIONS OF THE MATRICES UNDER OPERATION MUST BE SAME.

Page 11: Matlab 1(operations on_matrix)

Multiplication of two or more matricesNote: For multiplication operation to be successful, the number of columns of first matrix must be equal to the number of row s of second matrix.Ie: if A is a matrix of order mxn and B is a matrix of order nxp, then the expression C=A*B will result a matrix C of order mxp.

Page 12: Matlab 1(operations on_matrix)

Multiplication of two or more matricesMAT has order 3x3 and mat6 has order 3x2 , thus mat9 = mat*mat6 gives a new matrix mat9 having order 3x2.

Page 13: Matlab 1(operations on_matrix)

Multiplication errorThis is the error message we get when the basic multiplication rule is violated.

Page 14: Matlab 1(operations on_matrix)

THANKYOU.