MatlabTutorial Lec1
MatlabTutorial Lec1
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
Matlab Interface
Change the current
directory to the
location of your
Matlab file at
startup
Workspace
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 (contd)
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
(1) continuous-time system
(2) discrete-time system
Can compute and graph
(1) time response
(2) frequency response
Demo (1)
Transfer Function
Syntax: tf(numerator, denomintor)
Demo (2)
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