Vous êtes sur la page 1sur 22

ES205 Analysis and Design of Engineering Systems: An Introductory Tutorial: Getting Started with SIMULINK

Lab 1:

What is SIMULINK? SIMULINK is a software package for modeling, simulating, and analyzing dynamic systems. It supports linear and non-linear system modeling in continuous time, sampled time, or a combination of the two. It provides a graphical interface for building models as block diagrams using the mouse by click-and-drag operations. It also provides a variety of simulated output devices that can be attached to the system to monitor the output or state variables of the system. By defining the system graphically, the mathematical calculations required to simulate the differential equations that represent the models are hidden from your view. You only need to be able to supply the model structure and parameters, the simulation parameters, and the output variables and forms. You don't have to get bogged down in the math to determine the behavior of the system of interest. This tutorial will consist of 4 parts: A) Launching and becoming familiar with the SIMULINK environment B) Creating a simple 1st order model C) Creating a 2nd order model of a mass, spring, damper system D) Creating a model on your own of an electrical system. Part A: Launching Simulink: 1) SIMULINK is run from the MATLAB prompt, >>, so the first step is to get MATLAB running. -- Connect to the Network -- Launch MATLAB. ( if you have not already installed MATLAB you will need to do so at this time. Refer to the instructions handed out in Le 01.) 2) At the prompt, >>, in the MATLAB Command Window, type simulink and press

Enter.

ES205 Getting started with Simulink

Page 1 of 16

3) When SIMULINK opens you will see the box called the SIMULINK Library Browser. The Library consist of a number of different SIMULINK blocks with which a system model may be built. To build a model, you first need to create a space to make the model. Click the new model icon in the upper left corner to open a new SIMULINK file workspace. Next, select the SIMULINK icon to expand the list of the available elements that are used to create a system model.

4) After making the selections in Step 3, the SIMULINK Library Browser will show folders that contain the most commonly used elements you will be using for model creation. Click on each of the following folders and quickly note the elements that are contained in each. -- Continuous -- Discrete -- Functions & Tables -- Math -- Nonlinear -- Signals & Systems -- Sinks -- Sources When needed, these elements may simply be clicked, dragged, and dropped into the model workspace.

ES205 Getting started with Simulink

Page 2 of 16

During Step 3 you also opened a window called Untitled, which is the model workspace where the models will be created.

5) You have not yet created a model, but if you had, you would want to be able to save the model. To save a model, pull down the File menu and select Save_As or Click on the File Save Button While we won't save a file right now, we will have you create a new folder to save any models you will create. Create a new folder called, simulink_files by clicking on on the new folder button. and supply the correct name.

ES205 Getting started with Simulink

Page 3 of 16

Part B) Example 1: A Simple Model 1) The first model you are going to build will solve a simple 1st order differential equation given by

dx = 3 sin( 2 t ) dt
with an initial condition x(0) = -1. 2) To create a model of this equation, we first sketch a simulation diagram of the mathematical model. The simulation diagram will consist of: an input --> the forcing function, 3 sin(2t) an output --> the solution, dx/dt a parameter --> the initial condition, x(0) = -1 an operator --> integration block I.C.: x(0) = -1 dx dt

input: 3sin(2t)

1 s

output: x(t)

3) To construct this model in Simulink, will require three elements: -- a Sine Wave Block --an Integrator Block -- a Scope Block Locate the Sine Wave under the Sources folder and Click, Drag, and Drop it in the model workspace window to create the Input Block

ES205 Getting started with Simulink

Page 4 of 16

4) Locate the Integrator under the Continuous folder and Click, Drag, and Drop it in the model workspace window to create the Operator Block.

5) Locate the Scope under the Sinks folder and Click, Drag, and Drop it in the model workspace window to create the Output Block

ES205 Getting started with Simulink

Page 5 of 16

6) Connecting the blocks. Blocks can be connected by dragging a line from the output of one block to the input of another block. Make the following connections: Output of the Sine Wave --> Input of the Integrator Output of the Integrator --> Input of the Scope

The arrows indicate the direction of the signal flow. 7) Selecting Simulation Parameters. Most blocks have different parameters that are associated with them. To access the parameters, simply double-click on the block of interest. This will bring up a dialog box which allows the parameters to be changed. Double click on the Sine Wave and set the following parameters: Amplitude = 3 Frequency = 2

ES205 Getting started with Simulink

Page 6 of 16

Double click on the Integrator Block and set the parameter for the initial condition. x(0) = -1

Double Click on the Scope Block. This does not have any parameters which need setting, but instead displays the scope display screen.

8) Now that the model has been defined and created, the model simulation is ready to run. To Start a simulation, pull down the Simulation menu, and select Start. View the output of the simulation on the Scope window.

ES205 Getting started with Simulink

Page 7 of 16

9) Simulation Results Your results should look like the figure. Measure the magnitude of peaks and valleys and the period of the signal. Peak = ____________ Valley = ____________ Period = ____________

10) Simulation Verification: To verify that this plot represents the solution to the problem, let's solve the equation another way. Either manually, or using Maple, obtain the solution x(t) of the ODE with the initial condition

dx = 3 sin( 2t ) dt
Show solution here:

with x(0) = -1

The result should be:

x (t ) =

1 2

3 2

cos (2 t )

This is the function that was plotted in the SIMULINK Scope window. Save this SIMULINK model in the simulink_files folder as as Example1.mdl
ES205 Getting started with Simulink Page 8 of 16

Part C: Example 2, a mass, spring, damper system 1) The second model will use SIMULINK to create a model of a mass-springdamper system which may be modeled with a 2nd order differential equation. Other parameters of the system include: -----initial conditions: x(0) = 0 and dx/dt(0) = 0 the input f(t) is a step function with magnitude 3 at t=0 mass, m = 0.25 damping coefficient, c = 0.5 spring constant, k = 1

The model equation:

d 2x dx m 2 +c + kx = f ( t ) dt dt
Assume all units are consistent for the model. You will work through the following steps: a) Draw the simulation diagram b) Create and save the SIMULINK Model c) Run the Simulation. 2) In the space below attempt to draw the simulation diagram for this model:

ES205 Getting started with Simulink

Page 9 of 16

3) Let's walk through the steps. For comparison, start by solving the model equation for the highest order derivative term.

d 2x dx m 2 = f (t ) c k x dt dt
The first block you create should be a Sum block, where the output of the Sum block is the left-hand term of the equation above. d2x m dt2

sum block
Now using SIMULINK, Create a new workspace..... File ..... New.....Model Locate the Sum Block in the ____________ library and Click, Drag and Drop it into your new workspace.

The Sum block is to have 3 inputs. Double click on the Block and set the parameters to rectangular and + - - .
ES205 Getting started with Simulink Page 10 of 16

4) Gain Block. Add a gain (multiplier) block to normalize the coefficient, m, to modify the signal so it is equal to the highest order derivative term alone. d2x dt2 d2x dt2

1 m gain

sum block

Click, Drag, and Drop a Gain Block from the _____________ library into the SIMULINK workspace.

Double-click on the Gain block to change the block parameters. Use a Gain of ___________________ Add a title to the Gain Block.

ES205 Getting started with Simulink

Page 11 of 16

5) Add two integrators to your Simulation diagram. d2x dt2 d2x dt2 dx dt

1 m gain

1 s
Integrator

1 s

sum block

Integrator

Click, Drop, and Drag two Integrator Blocks into your SIMULINK workspace from the _______________ library. Also: Set the initial condition parameters to zero for both integrators. Add a scope block to the output of the second integrator Connect the output ports to the input port as shown Label each of the signals by double clicking on the leader line.

ES205 Getting started with Simulink

Page 12 of 16

6) Return Branch Gain Blocks In the Simulation Diagram, connect the integrated signals with gain blocks to create the terms on the right-hand side of the model equation. d2x dt2 d2x dt2 dx dt

1 m

1 s
c k

1 s

sum block

dx dt

kx

In SIMULINK, Drag in two additional Gain blocks from the Math library to the workspace. --Flip these blocks by selecting each block and using...... Format.......Flip Block --Double click on each of the blocks and set the appropriate parameters c = 0.5 k = 1.0 --Connect the signal lines: Either Click the gain block input and drag to each of the branch points. or Ctrl-Click to select the branch point first and drag to the gain inputs. --Add appropriate titles to the gain blocks

c = 0.5

k = 1.0

ES205 Getting started with Simulink

Page 13 of 16

7) Connect all Input Signals. In the Simulation Diagram, connect all the input signals to the appropriate inputs of the Sum Block. Input: f(t)

+ -

d2x dt2

1 m

d2x dt2

1 s
c k

dx dt

1 s

Output: x(t)

dx dt

kx

In the SIMULINK workspace: -- Add a Step Block from the Source library and set its parameters. Step time = 0 Initial value = 0 Final value = 3 -- Connect the signal lines to the sum Block, paying attention to the signs of the inputs.

ES205 Getting started with Simulink

Page 14 of 16

8) Your completed SIMULINK model should look like the following. Complete any missing titles or labels.

Save your model as Example2.mdl

9) Running your simulation Double click on the Scope to make its output visible. Run your simulation. What is it maximum value of x reached?______________ What is its final value of x reached?__________________ Is this behavior underdamped, overdamped, or critically damped?

ES205 Getting started with Simulink

Page 15 of 16

This concludes the SIMULINK Tutorial Module. You are now to complete Part D: Lab 1 Worksheet. To complete the worksheet you are expected to understand and use the terms below. Terms used on the worksheet: Steady State Value is the final value of the system settles at after transient behavior has dissipated. Overshoot is characterized as the maximum response swing past the steady state value. Rise time is time required for the system to first reach the steady state value. Settling time is the amount of time the system takes to value settle close to the steady state condition (to within approximately 5% of the step size). .
Settling Time

Overshoot

Steady State Value +/- 5% of step

Rise Time

time

ES205 Getting started with Simulink

Page 16 of 16

Name __________________________Section _______ C M _____________ Lab Partners: ________________ __________________ _______________

Part D: Lab 1 Worksheet ES205 Analysis and Design of Engineering Systems


1) Mass-Spring-Damper Model: Below you will explore how changing each of the three parameters, m, c, and k , affect the system response of the spring-mass-damper model created in Part C. Varying the mass, m: In the space below, make a prediction. How do you think changing the mass, m, of the system will affect its dynamic behavior?

Now using your SIMULINK model, vary the value of the mass, m, using the multipliers given below, while keeping k and c constant. Then on the graph below sketch and label each response. Use Mass values:
5 4.5 4 3.5 3 2.5 2 1.5 1 0.5 0 0 1 2 3 4 5 6 7 8 9 10

m/5

m/2

1.0*m

2.0*m

and

5*m

Summary: Give a short summary which qualitatively describes how changing the mass affected the system response. Include qualitative reference to the overshoot, settling time, and steady state value.

ES205 Lab 1 Worksheet

Page 1 of 6

Varying the damping constant, c: Make another prediction. How will changing the damping constant, c, of the system affect its dynamic behavior?

Now using your SIMULINK model, vary the value of the mass, c, using the multipliers given below, while keeping k and m constant. Then on the graph below sketch and label each response. Use Damping Constants:
5 4.5 4 3.5 3 2.5 2 1.5 1 0.5 0 0 1 2 3 4 5 6 7 8 9 10

c/5

c/2

1.0*c

2.0*c

and

5*c

Summary: Give a short summary which qualitatively describes how changing the damping constant affects the system response. Include qualitative reference to the overshoot, settling time, and steady state value.

ES205 Lab 1 Worksheet

Page 2 of 6

Varying the elastic coefficient, k: Make a prediction: How will changing the elastic coefficient, k, of the system affect its dynamic behavior?

Now using your SIMULINK model, vary the value of the elastic coefficient, k, using the multipliers given below, while keeping m and c constant. Then on the graph below sketch and label each response. Use Elastic Coef values:
16 14 12 10 8 6 4 2 0 0 1 2 3 4 5 6 7 8 9 10

k/5

k/2

1.0*k

2.0*k

and

5*k

Summary: Give a short summary which qualitatively describes how changing the elastic coefficient affected the system response. Include qualitative reference to the overshoot, settling time, and steady state value.

ES205 Lab 1 Worksheet

Page 3 of 6

2) Modeling a Simple Electrical RLC Circuit. A simple electrical circuit consists of a Resistor, Coil, and Capacitor in series with a variable voltage source, E(t). R i

+ -

E(t)

The circuit may be modeled using two 1st order DE's given as

di R 1 1 + i + e = E (t ) dt L L L
with i(0) = 0

and

de 1 i=0 dt C
with e(0) = 0

where i is the current in the circuit and e is the electric potential at the node between the coil and capacitor. Draw the Simulation Diagram that represents these DEs below.

ES205 Lab 1 Worksheet

Page 4 of 6

Now using your Simulation diagram, create the SIMULINK model for this electrical system using the values: R=3 L=1 E(t) C =0.5 and E(t), which is a pulse defined as

2 t 1 5

Add Scope Blocks to display both outputs, i and e, as well as the input voltage, E(t). Make sure you include appropriate labeling of the blocks, signals, and I/O. Run the simulation for 0< t < 10 Sketch the shape of the output signals below: e i

Now experiment with your model by varying each of the component parameters, R, L, and C. Describe the effect each has on the system response. Effect of Varying R:

Effect of Varying L:

Effect of Varying C:

ES205 Lab 1 Worksheet

Page 5 of 6

Using trial and error, try to select an appropriate set of values for R, L, and C that produce a system response such that the system has -- a rise time of less than 1 s -- a settling time less than 4 s -- an overshoot of less than 0.25 V? Document the variations you tried to produce this response on the table below. (If after 8 tries you were unable to find a satisfactory solution you may stop.) Trial 1 2 3 4 5 6 7 8 R L C
Settling Time Overshoot Meet Constraints?

Upon completion of this Worksheet, hand in the following: 1) This handout, Part D with all graphs, tables, and questions completed. 2) A printed copy of your spring-mass-damper system SIMULINK model. 3) A printed copy of your electrical system SIMULINK model.

ES205 Lab 1 Worksheet

Page 6 of 6

Vous aimerez peut-être aussi