Vous êtes sur la page 1sur 23

Intro.

to
MATLAB
By Hisham Abuella
TA & RA in ECE @ Istanbul ehir University
Email : hishamabuella@std.sehir.edu.tr

Outline
Where to use MATLAB ?
What is Matlab & Why use it ?
MATLAB Desktop
Exercise 1
Matrices & Vectors
Exercise 2
Useful Sites

Where to use MATLAB ?


Dealing with Matrices and Arrays
2-D and 3-D Plotting and graphics
Linear Algebra
Algebraic Equations
Statistics
Data Analysis
Calculus and Differential Equations
Numerical Calculations
Integration
Transforms
Curve Fitting

What is Matlab & Why use it ?


Stands for MATrix LABoratory
Interpreted 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 Desktop
1- Command Window
2- Command History
3- Workspace
4- 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 desktop


https://youtu.be/PfklSSxZSZU?t=43s

Exercise 1

Hint
:
^ : power
sqrt: square root
= (2^3)

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

Matrices & Vectors - I


Nearly every thing in MATLAB is in matrices
Easy to define: >> A = [16 3; 5 10]
A =

16
5

3
10

, or to separate row elements


use ; to separate rows
Use

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 - II


Vectors - special case
-n=1
- m=1

column vector
row vector

The : operator
VERY important operator in Matlab
Means to
>> 1:10
ans =
1

10

The : operator and matrices


For Matrix
>>A(3,2:3)
ans =
1

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

Creating Vectors
1- Create vector with equally spaced intervals
x=0:0.5:pi
2- Create vector with n equally spaced intervals
x=linspace(0, pi, 7)

Note: MATLAB uses pi to represent


imaginary unit

, uses i or j to represent

Creating Matrices
zeros(m, n): matrix with all zeros
ones(m, n): matrix with all ones.
eye(m, n): the identity matrix
randn(m, n): normally distributed random

Operations can be done :

+: addition

-: subtraction

^: exponentiation

*: multiplication

/: division

Manipulating Vectors
Evaluated element by element
.'
.^
.*
./

:
:
:
:

array
array
array
array

transpose (non-conjugated transpose)


power
multiplication
division

Manipulating Matrices

Try These :

>> A ' % transpose


>> B*A

-For :

% 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

A=
4
1
5
-1
2
7

&

2
4
0

B=
-1
1
4
8
2
2

3
6
0

Some Built-in functions


mean(A):mean value of a vector
max(A), min (A): maximum and minimum.
sum(A): summation.
sort(A): sorted vector
median(A): median value
det(A) : determinant of a square matrix
Inv(A): Inverse of a matrix A

Exercise 2

Exercise 2 (Continue)

Hint : use A\B

Solutions
https://youtu.be/pTdkD1UpGjU?t=28s

HW

Useful Sites
http://www.see.ed.ac.uk/teaching/courses/matlab/
http://www.tutorialspoint.com/matlab/matlab_overview.
htm
http://www.mathworks.com/help/matlab/index.html
http://www.mathworks.co.uk/matlabcentral/

Next session ...


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

Vous aimerez peut-être aussi