Академический Документы
Профессиональный Документы
Культура Документы
Matlab Tutorial
Jan 29 2008
Outline
What is Matlab?
Matlab Interface
Basic Syntax
Plotting Graphs
Control System Toolbox
Examples
Useful Resources
Overview of Matlab
What is Matlab?
Language for technical computing
Supports mathematical computation,
visualization, and programming
Composed using high-level
programming language
similar to syntax of C
Command
History Command Window
Matlab Programming
Two Approaches
Coding in Command Window
Good for short programs
Commands must be re-entered each time you run
a simulation
Write your
commands here
(1) Creating .m-files
File New M-
File
Write your
commands here
Types of plots
- Solid line
-- Dashed line
: Dotted line
-. Dashdot
line
Syntax: plot(x,’-’)
Plotting Graphs (cont’d)
Labeling Graphs
Commonly used Syntax:
ylabel(‘text’) – label y-axis
xlabel(‘text’) – label x-axis
title(‘text’) – label title
legend(‘legend1’, ‘length2’,…) – puts legend on
current plot
grid on (grid off) – add (remove) grid lines to figure
subplot – subdivides graphic window
hold on – hold the previous plot on the graphic
window
Example (1)
Example (2)
subplot(2,2,1) subplot(2,2,2)
plot(x,’r’),hold on plot(x,’r’),hold on
plot(y,’--’) plot(y,’--’)
subplot(2,2,3) subplot(2,2,4)
plot(x,’r’),hold on plot(x,’r’),hold on
plot(y,’--’) plot(y,’--’)
Examples on
Plotting Graphs
Control System Toolbox
Overview to the Toolbox
Modeled control systems as
(1) transfer functions
(2) zero-pole-gain
(3) state-space form
Can manipulate both
State-space Representation
Syntax: sys_ss = ss(sys)
Demo (3)
Finding Poles and Zeros
Syntax: z = zero(sys)
p = pole(sys)
Pole-Zero Diagram
Syntax: zplane(z,p)
Demo (4)
Closed-Loop System
Syntax: CLsys = feedback(sys1,sys2)
+
System 1
-
System 2
Demo (5)
Step Response
Syntax: step(sys)
Demo (6)
Pole-zero cancellation
Syntax: sysr = minreal(sys);
Impulse Response
Syntax: impulse(sys)
Examples on
Control System Toolbox
Useful Resources
Appendix A of Textbook
http://www.mathworks.com