









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
tutorial for simulink lab , introduction and building simple models
Typology: Lecture notes
1 / 17
This page cannot be seen from the preview
Don't miss anything!
Christopher Lum lum@u.washington.edu
This document is designed to act as a tutorial for an individual who has had no prior experience with Simulink. It is assumed that the reader has already read through the Beginner and Intermediate MATLAB Tutorials. For any questions or concerns, please contact
Christopher Lum lum@u.washington.edu
Figure 1: Starting Simulink using icon or Command Window
Figure 2: Simulink interface
METHOD 1: 2nd^ Order Ordinary Differential Equation
( ) zt m
c zt m
k ut m
z && t = − − & Equation 1
Figure 4: Model with two integrators and a step function
values 1 / m , k / m , and c / m , respectively. For this problem, let k = 2 , c = 0. 5 , and m = 1. We can multiply the signals using a ‘gain’ block which is found in the ‘Math Operations’ group. Draw three ‘gain’ blocks into your model and connect them appropriately. (Hint: You can flip the orientation of the block by right click
Format > Flip Block).
Figure 5: Model with integrators, step function, and gain blocks.
Figure 6: Parameters for the ‘Gain’ blocks.
Figure 7: Parameters for the 'Sum' block
a. Click on the “Run” button b. Go Simulation > Start c. Using the “sim” command from the Command window.
For now, simply use option a or b, we will visit using option c later.
a) u(t) signal (^) b) z(t) signal
Figure 10: Output from scope outputs
METHOD 2: State Space Representation
Recall that in addition to using a second order ODE to model the system, we can use a state space representation of this system of
x &^ = Ax + Bu Equation 2
y = Cx + Du
where (^)
k m c m
m
Once again, let k = 2 , c = 0. 5 , and m = 1.
Figure 11: Simulink model with just state space block added
Enter in the A, B, C, and D matrices. Leave the initial conditions as 0. (Note that
Let’s analyze how the system response changes if we use different damping coefficients of c = 0.5, 1.0 and 1.5.
This would be very tedious if we had to change the A matrix each time by hand and then simulate the system and then look at the plot. Therefore, we will use the m-file to write a script which will do this for us.
Figure 14: State space block parameters using variables as parameters
Variable Name Class Comments sim_u struct array Created by 1st^ “To Workspace” block sim_y struct array Created by 2nd^ “To Workspace” block tout double array Automatically created by Simulink when you run a model
Functions: sim Note: For our purposes, use sim with only 1 argument, the name of the model which you are trying to run
Functions: max, find, Note: Here is an example of how to use these functions
Functions: figure, hold on, plot, grid, xlabel, ylabel,legend, num2str Note: The num2str function is one of the most useful plotting functions. Be sure that you understand how to use it.
The output of this code should appear as
Functions: for, length, … Note: The “…” symbol mean continue typing on the next line. This allows a very long line of code be broken up into two separate lines.
The output should look like
Version History: 09/28/04: Created: 11/23/05: Updated: made this format match other to-do documents and removed references to AA547. 12/01/05: Updated: changed header to match how-to template 12/09/05: Updated: Made changes to layout and added footer. 10/31/06: Updated: Fixed typo of "Tout" to "tout" 11/01/06: Updated: Touched up some of the graphics. 09/15/09: Updated: Added 2nd^ order ODE method. 09/25/10: Updated: Minor changes