Professional Documents
Culture Documents
Introduction to Matlab
Matlab Basics
Branching Statements
Loops
User Defined Functions
Additional Data Types
Input/Output Functions
Simulink Toolbox
Important Toolboxes (if time is available)
Dr. Nidal Farhat
Mechanical Engineering Department
Objectives:
Variables and Arrays
Initializing Variables in MATLAB
Multidimensional Arrays
Subarrays
Special Values
var = [1 2 3 4];
a = [0 1+7];
a = [0 8]
b = [ a(2) 7 a];
b = [8 7 0 8]
c(2,3) = 5;
c= 0 0 0
0 0 5
Multidimensional Arrays
Multidimensional Arrays
Array as introduced
Subarrays
Subarrays
1. The end Function (highest value of a given subscript)
Subarrays
3. Assigning a scalar to
a subarray
Special Values
*.mat
text format (ascii)
*.mat
text format (ascii)
Very important
Hierarchy of Operations
Distance = 0.5 * acceleration* (time^2)
Distance = (0.5 * acceleration* time)^2
Class Work
Optional
2. Most of functions
accept array inputs
Plotting in Matlab
If no filename is specified,
plot is printed on the printer
Multiple plots
Plot the following functions on the same figure
f(x) = sin(2x) and its first derivative over x = 0:pi/100:2*pi
Multiple plots
Plot the following functions on the same figure
f(x) = sin(2x) and its first derivative over x = 0:pi/100:2*pi
NW
NL
NC
NR
NE
TW
TL
TC
TR
TE
MW
ML
MC
MR
ME
BW
BL
BC
BR
BE
SW
SL
SC
SR
SE
Limits of
plot axes
Be aware of the version of Matlab you are using, see help legend
Mechanical Engineering Department
Logarithmic Scale
>> plot
>> semilogx
>> semilogy
>> loglog
Example
Home Work
Solve the following problems
2. [9, 10 , 11, 16]