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
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
Legal Examples:
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
3. Preallocating arrays.
recall: arr = 1:4; arr(7) = 8; arr == [1 2 3 4 0 0 8]. (i.e. Matlab
automatically extend/change the size of the array.
It is better to preallocate the array before THE for LOOP to make the
program much more faster.
CH4: LOOPS
Faster
CH4: LOOPS
CH4: LOOPS
continue
CH4: LOOPS
ii
jj
Output
product
CH4: LOOPS
ii
jj
Output
product
CH4: LOOPS
CH4: LOOPS
Logical array
CH4: LOOPS
CH4: LOOPS
Faster
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
CH4: LOOPS
y (t ) y0 v y0 t 12 gt 2
v y0 v0 sin( )
x(t ) x0 vx0 t
t 0,
vx0 v0 cos( )
t
2* v y0
g
CH4: LOOPS
y (t ) y0 v y0 t 12 gt 2
v y0 v0 sin( )
x(t ) x0 vx0 t
t 0,
vx0 v0 cos( )
t
2* v y0
g
CH4: LOOPS
Home Work
Solve the following problems:
4.[16, 19, 21]
CH4: LOOPS