Post on 02-Apr-2018
transcript
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 1/22
Introduction toMATLAB
Chris DiduchUniversity of New Brunswick
January 31 – February 4, 2004
Royal Bhutan University
RBIT, RinchendingDay-4
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 2/22
Interpolation
x x f y x ),(,
i x
Interpolated values are f ( xi)
x
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 3/22
Interpolation
)0()0( y y
f t
x
)()( f f t yt y
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 4/22
Nonlinear Algebraic Equations
1)(
1)(
j
e j P
s
e s P
j s
0)(Im j P
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 5/22
Pendulum Dynamics
0sin 2 ml Bmgl
mg
θ
2
122
21
21
sin
,,:
ml
xmgl Bx x
x x x x Let
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 6/22
The MATLAB Programming
Language: Days 1-2
Matlab windows
Arrays: create, append, index
Matrix and element-by-element operations Functions and scripts
Relational and logical operations
Structured programming: if, while, do, switch Basic plotting
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 7/22
Data Analysis: Day 3
Solving linear equations
Eigenvalues and eigenvectors
Linear algebra Linear least sqares problems
Polynomials: multiply, divide, evaluate,
residues and roots. Curve fitting.
Numerical integration.
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 8/22
Data Analysis: Day 3
Interpolation
Solving nonlinear algebraic equations
Finding the minimum value of a function Numerical solution to ODE’s
Sound and audio
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 9/22
Proposed Topics for Day-4
2-D Graphics
3-D Graphics
Animation Simple GUI’s
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 10/22
Overlaying Plots
plot() with multiple data sets
hold on, multiple plot()’s, hold off
Create a new figure() window Use subplot()
Use the low level primitive, line()
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 11/22
2D Plots
Plot functions
Semilog and loglog plots
Polar plots Filled plots, Pie and Bar charts, Histograms
Error bar
Step and staircase Comet
Contour and quiver plots
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 12/22
3D Plots
Plot a line in 3D, plot3()
Polygons in 3D
Contour plots Surface plots
Interpolated surface plots
Shapes: sphere, ellipsoid, cylinder
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 13/22
Handle Graphics
Each object in a fig window is assigned and
identified by a number called its handle.
Objects are related through a hierarchy.
Objects have a set of default properties.
The properties may be changed using set()
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 14/22
Example
t=linspace(0,pi,50)
x=t.*sin(t)
hL=line(t,x)get(hL)
set(hL,'linestyle','--')
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 15/22
MATLAB Object Hierarchy
Figure
Uicontrols Axes Uimenus
Line Patch Text Image
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 16/22
Graphics and Animation
line() % Create line object
set() % Update object
% attributes drawnow() % Update figure window
clock % Return current time
etime() % Return elapsed time
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 17/22
An Orbiting Dot
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 18/22
Animate a Phasor
sin ωt
t
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 19/22
Multiple Axes in the same
Figure Window
HandleAx = AXES('position', RECT)
Opens up an axis at the position, RECT. RECT = [left, bottom, width, height]
Relative to the lower-left corner of the Figwindow, in normalized units.
(0,0) is the lower-left corner and (1.0,1.0) isthe upper-right.
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 20/22
Animate the Pendulum
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 21/22
Pendulum Animation
Animation updates are
governed by the laws of
motion.
Euler’s method gives:
2
111
1
sin
ml
mgl B
t
t
k k k k k
k k k
7/27/2019 Overheads Day 4
http://slidepdf.com/reader/full/overheads-day-4 22/22
Animate the Pendulum-2
ω vs t ω vs θ
θ vs t Animation