lecture on matlab simulink
TRANSCRIPT
-
7/24/2019 Lecture on Matlab Simulink
1/12
ECE5143 Linear Systems and ControlLecture on Matlab/Simulink
Yongcan Cao, Assistant ProfessorDepartment of Electrical and Computer EngineeringUniversity of Texas, San Antonio
-
7/24/2019 Lecture on Matlab Simulink
2/12
Linear Time-Invariant Systems (LTI)
LTI systems: = + , = +
lsim (matlab command)
For example:A = [-1 0; 0 -1];
B = [1;1];C = [1 0];D = 0; sys = ss(A,B,C,D);For example, t = 0:0.01:10; u = sin(t); lsim(sys,u,t) simulates the responseof a single-input model SYS to the input u(t)=sin(t) during 10 seconds.
Other examples: step, impulse,
-
7/24/2019 Lecture on Matlab Simulink
3/12
Linear Time-Invariant Systems (LTI)
LTI systems: = + , = +
[u,t] = gensig('square',4,10,0.1);H = [tf([2 5 1],[1 2 3]) ; tf([1 -1],[1 1 5])];lsim(H,u,t);
Other methods: solving differential equations using ODE45.
[t,x]=ode45(@reactor,[0 10],[0.1;40],[],55);
function dx = reactor(t,x,Tj)
dx =[dCa;dT]
-
7/24/2019 Lecture on Matlab Simulink
4/12
Simulink
-
7/24/2019 Lecture on Matlab Simulink
5/12
S-function (M-file+Simulink)
What is S-Function? S-Functions is computer language description of Simulink block If written in MATLAB programming environment it is called M-file s-
function If written in C/C++ programming environment it is called C Mex s
function
What can S-Function Do? Allows you to add your own code to simulink model or environment Code can be written for continuous, discrete or hybrid system
-
7/24/2019 Lecture on Matlab Simulink
6/12
-
7/24/2019 Lecture on Matlab Simulink
7/12
How does S-function work?Mathematically Simulink block consist of a set of inputs u, a set of states x, and set of outputs y
M-files:Initialization port widths, data types, sample time, memories allocation, execution order, evaluates b
parametersSimulation loop Execute block determined during initialization, computes/updates blocks states, deand outputs during a sample time
-
7/24/2019 Lecture on Matlab Simulink
8/12
-
7/24/2019 Lecture on Matlab Simulink
9/12
Mobile Robot
= cos = sin
=
( , ) is the 2D location of the robot, is the heading of the robot,linear velocity of the robot, and is the angular velocity of the robot.
-
7/24/2019 Lecture on Matlab Simulink
10/12
Simulate a Robot using S-function
robot.m s-function describing robot kinematics w: linear speed w: angular speed
-
7/24/2019 Lecture on Matlab Simulink
11/12
Simulate a Robot with a Controller using S-function
robot.m: s-function describing robot kinematics ctrl.m: s-function describing the control input for the robot w: linear speed w: angular speed
-
7/24/2019 Lecture on Matlab Simulink
12/12
S-function Manual
http://www.mathworks.com/help/pdf_doc/simulink/sfunctions.pdf