Professional Documents
Culture Documents
Applications
(0904 201)
Dr. Lubna
Badri
Second
Semester
2013-2014
Course
Overview
Office: 9108,
Engineering Building
Office Hours: Sun, Tue, & Thu. 11:00 12:00,
or by appointment
Email: Lbadri@zuj.edu.jo
Course Website:
http://lbadri.com/?page_id=355
Course Objectives
o
o
o
o
Text Book
Introduction to MATLAB for Engineers William J.
Palm
.III, 2010
What is MATLAB?
A
software
environment
for
interactive
numerical computations.
MATLAB allows:
Matrix manipulations,
Plotting of functions and data,
Implementation of algorithms,
Creation of user interfaces, and
Interfacing with programs written in other
languages, including C, C++, Java, and Fortran.
Matlab Background
Matlab = Matrix Laboratory
Originally a user interface for numerical
linear
algebra routines
Commercialized 1984 by The Mathworks
Alternatives
Complements
Matrix-X
Octave
(symbolic)
Lyme
(free; GNU)
(free; Palm)
Maple (symbolic)
Mathematica
Matlab Desktop
Launch Pad
Command
Window
History
Matlab Desktop
Workspace
Command
Window
Current
DIrectory
MATLAB Demo
Demonstrations are invaluable
since they give an indication of the
MATLAB capabilities.
A comprehensive set are available
by typing the command >>demo in
MATLAB prompt.
Interactive Calculations
Interactive Calculations
Most elementary functions and constants are
already defined
>> cos(pi)
>> abs(1+i)
>> sin(pi)
Last call gives answer 1.2246e-016 !?
Variables
Dont have to declare type
Dont even have to initialise
Just assign in command window
>>
>> a=12; % variable a is assigned 12
Variables
Workspace
>> b=10;
>> c=a+b
c=
22
>>
Order
of Precedence
1.
Parentheses,
evaluated starting
innermost pair.
with
the
equal
equal
=The
Assignment
Operator
Typing x = 3 assigns the value 3 to the variable
x.
We can then type x = x + 2.
This assigns the value This assigns the value 3 + 2
= 5 to. x. But in algebra this implies that 0 =
2.
In algebra we can write x + 2 = 20, but in
MATLAB we cannot.
In MATLAB the left side of the = operator must
be a single variable.
The right side must be a computable value.
Arrays
Array Index
>>u(7)
ans =
0.6000
ans =
2.8232
Use the lengthfunction to determine how many values are in
an array.
>>m = length(w)
m= 101
Matrix Operators
>> v + 2
>> B = A
>> A*B
>> A+B
Indexing Matrices
Indexing Matrices
Index complete row or column using
the colon operator
>> A(1,:)
Can also add limit index range
>> A(1:2,:)
>> A([1 2],:)
General notation for colon operator
>> v=1:5
>> w=1:2:5
Matrix Functions
Many elementary matrices predefined
>> help elmat;
>> I=eye(3) % EYE Identity matrix.
Manipulating Matrices
>>
>>
>>
>>
>>
>>
>>
A'
B*A
B.*A
B/A
B./A
[B A]
[B; A]
%
%
%
%
%
%
=A
1
0
7
3
5
2
5
2
1
4
2
% transpose
2
1
matrix multiplication
1
element by element multiplication
matrix division
element by element division
Join matrices (horizontally)
=B
1 3
Join matrices (vertically)
9
7