Intro to Matlab 2

Post on 14-Jul-2016

227 views 0 download

description

Intro to matlab

Transcript of Intro to Matlab 2

Intro To MATLAB Intro To MATLAB 22

Prepared by Prepared by Eng: Ahmed EmadEng: Ahmed Emad

Some Of OperationsSome Of Operations

* To get square function of any number* To get square function of any numbersqrt (no)sqrt (no)

*To get the complex number of any number*To get the complex number of any numberi (enter keyboard)i (enter keyboard)

• Command (Clear) to make clear to all variables from Command (Clear) to make clear to all variables from Work spaceWork space

Trigonometric Functions MATLAB measure the angle by MATLAB measure the angle by

radianradian

Matrices Group of data appear in such Group of data appear in such

row, columnrow, column

To write matrix like thatTo write matrix like thatArr=[1;3;5]Arr=[1;3;5]Every element is an rowEvery element is an row

How To Write Matrix In How To Write Matrix In Different waysDifferent ways

Operation on MatricesOperation on Matrices The operations on matrices areThe operations on matrices are1-addition1-addition2-subtraction2-subtraction3-multiplication3-multiplication4-divition4-divition

Addition:Addition:Condition:Condition:we add two matrix when the two

matrix are equal in row & column

Subtraction:Subtraction:Condition:Condition: is the same as Additionis the same as Additionwe sub two matrix when the two

matrix are equal in row & column

Multiplication:Multiplication:Condition:Condition:the column of matrix 1 is equal to the row of the column of matrix 1 is equal to the row of

matrix 2matrix 2

Division:Division:We can get division in matrix such as to We can get division in matrix such as to

solve solve Equations like thatEquations like that

3x + 3y =33x + 3y =32x + 3y =52x + 3y =5

We can get the solution of two Eq: by We can get the solution of two Eq: by using 2using 2

MethodsMethods1-elimination1-elimination2-division of matrix2-division of matrix

Division of matrix:Division of matrix:

ContCont::

Vectors & matricesVectors & matrices Vector :Vector :Is a matrix but contain only one column Is a matrix but contain only one column

ororOne rowOne rowEx:Ex:A=[1;2;3;4;5;6] one columnA=[1;2;3;4;5;6] one columnOrOrB=[1 2 3 4 5 6]B=[1 2 3 4 5 6] one row one row

Operation On VectorsOperation On Vectors1- Length of vector:1- Length of vector: ex:ex:A = [1 2 3 4 5 6]; so length of vector can A = [1 2 3 4 5 6]; so length of vector can

getgetLength (A)Length (A)2-add an element to any vector2-add an element to any vectorEx: b=[1;2;3;4;5;6];Ex: b=[1;2;3;4;5;6];b(7)=9 b(7)=9 Note : matlab language is case sensitiveNote : matlab language is case sensitive

3-Add a group of elements:3-Add a group of elements:We have 2 ways:We have 2 ways:A=[1 3 4 5 6];A=[1 3 4 5 6];A(6)=7; A (7)=9; A (8)=10A(6)=7; A (7)=9; A (8)=10ORORA(6:8)=[7 9 10]A(6:8)=[7 9 10] or A(6:8)=[7;9;10] or A(6:8)=[7;9;10]

4-Eliminate an element:4-Eliminate an element:A(2)=[ ] we eliminate the element no 2 which is 3A(2)=[ ] we eliminate the element no 2 which is 3

5- 5- Eliminate a group of elements:Eliminate a group of elements:A(6:8)=[ ] we eliminate a group of elements from element A(6:8)=[ ] we eliminate a group of elements from element

No 6 to element no 8No 6 to element no 8

6-Max no of Vectors:6-Max no of Vectors:A=[1 4 5 8 9];A=[1 4 5 8 9];max (A)=9 max (A)=9 7-Min no of Vectors:7-Min no of Vectors:B =[11;4;6;7];B =[11;4;6;7];min (B) = 4min (B) = 4Note :Note : the word max & min is small not uppercasethe word max & min is small not uppercase8-Sum of vector:8-Sum of vector:Y=[1 3 5];Y=[1 3 5];sum (Y) = 9sum (Y) = 99-Product of Vector:9-Product of Vector:Y=[1 3 5];Y=[1 3 5];prod (Y) = 15prod (Y) = 15

Operations on MatricesOperations on Matrices1-Size of matrix:1-Size of matrix:

2-Add an element2-Add an element::B = [1 2 3;12 3 4;22 23 34];B = [1 2 3;12 3 4;22 23 34];B(2,4) = 4 where 2 is row no 2 and 4 B(2,4) = 4 where 2 is row no 2 and 4

is column no 4is column no 43-Add elements:3-Add elements:ss=[=[1212 22 3;113;11 33 33; 2233; 22 3333 4444]];;ss((4,1:44,1:4)=[)=[1212 4444 5555 3434]] is equal to is equal to1212 22 33 001111 33 3333 66662222 3333 4444 001212 4444 5555 3434

Cont . Add elements:Cont . Add elements:ss((1:4,51:4,5)=[)=[1212 3333 4444 5555]]1212 22 33 00 12121111 33 3333 6666 33332222 3333 4444 00 44441212 4444 5555 3434 5555