23
Intro. to MATLAB By Hisham Abuella TA & RA in ECE @ Istanbul şehir University Email : [email protected]

Intro to Matlab

Embed Size (px)

DESCRIPTION

By Hisham Intro to Matlab

Citation preview

Intro. on MATLAB

Intro. to MATLABBy Hisham AbuellaTA & RA in ECE @ Istanbul ehir UniversityEmail : [email protected]

OutlineWhere to use MATLAB ?What is Matlab & Why use it ?MATLAB DesktopExercise 1Matrices & VectorsExercise 2 Useful Sites

Where to use MATLAB ?Dealing with Matrices and Arrays2-D and 3-D Plotting and graphicsLinear AlgebraAlgebraic EquationsStatisticsData AnalysisCalculus and Differential EquationsNumerical CalculationsIntegrationTransformsCurve FittingWhat is Matlab & Why use it ?

Stands for MATrix LABoratoryInterpreted language (Line by Line)Scientific programming environment ( cos , sin , ....)Very good tool for the manipulation of matrices ( rank , inv ....)Great visualisation capabilities ( plot , stem ....)Loads of built-in functions ( Use help you will be surprised...) Easy to learn and simple to use ( Use help of matlab + lot of online examples ....)

MATLAB Desktop1- Command Window2- Command History3- Workspace4- Current Directory

How you will work on matlab this session ?1- Is the matlab installed on your computer ? search for matlab ...

2- Use http://www.tutorialspoint.com/matlab/try_matlab.php 01 The MATLAB desktophttps://youtu.be/PfklSSxZSZU?t=43s

Exercise 1

Solutions to Exercise 1https://youtu.be/rZuAns0iEt4?t=20s

Matrices & Vectors - INearly every thing in MATLAB is in matricesEasy to define: >> A = [16 3; 5 10] A = 16 3 5 10 Use , or to separate row elements use ; to separate rows Try the same line without the semicolon and comments

Access elements of a matrix >>A(1,2) ans= 3 Remember Matrix(row,column)

Matrices & Vectors - IIVectors - special case - n = 1 column vectorm = 1 row vector The : operatorVERY important operator in MatlabMeans to>> 1:10ans = 1 2 3 4 5 6 7 8 9 10 The : operator and matrices For Matrix

>>A(3,2:3)ans = 1 7>>A(:,2)ans = 2 1 1Whatll happen if you type A(:,:) ?

Creating Vectors1- Create vector with equally spaced intervals x=0:0.5:pi2- Create vector with n equally spaced intervalsx=linspace(0, pi, 7)

Note: MATLAB uses pi to represent , uses i or j to represent imaginary unit

Creating Matriceszeros(m, n): matrix with all zerosones(m, n): matrix with all ones. eye(m, n): the identity matrix randn(m, n): normally distributed randomOperations can be done :+: addition -: subtraction ^: exponentiation *: multiplication /: division

Manipulating VectorsEvaluated element by element.' : array transpose (non-conjugated transpose).^ : array power .* : array multiplication ./ : array division

Manipulating MatricesTry These : >> A '% transpose -For : &>> B*A % matrix multiplication>> B.*A% element by element multiplication>> A\B % left division same as INV(A)*B >> B/A % matrix division>> B./A % element by element division>> [B A]% Join matrices (horizontally)>> [B; A]% Join matrices (vertically)>> A-B % Subtract B from A>> A^2 % calculate A square

B = -1 3 1 4 6 8 2 0 2

A = 4 2 1 5 4 -1 2 0 7

Some Built-in functionsmean(A):mean value of a vectormax(A), min (A): maximum and minimum. sum(A): summation.sort(A): sorted vectormedian(A): median valuedet(A) : determinant of a square matrix Inv(A): Inverse of a matrix A

Exercise 2

Exercise 2 (Continue)

Hint : use A\B Solutionshttps://youtu.be/pTdkD1UpGjU?t=28s

HW

Useful Siteshttp://www.see.ed.ac.uk/teaching/courses/matlab/http://www.tutorialspoint.com/matlab/matlab_overview.htmhttp://www.mathworks.com/help/matlab/index.htmlhttp://www.mathworks.co.uk/matlabcentral/

Next session ...Plots in Matlab Try: stem , plot ......Relational & Logical Operators Try: && > == ||.....If-Else Statement For LoopsWhile Loops Functions and Scripts