DEPARTMENT OF SYSTEMS ENGINEERING -...

60
KING FAHD UNIVERSITY OF PETROLEUM & MINERALS COLLEGE OF COMPUTER SCIENCES & ENGINEERING Department of Systems Engineering SE 207 MODELLING AND SIMULATION LAB MANUAL

Transcript of DEPARTMENT OF SYSTEMS ENGINEERING -...

KING FAHD UNIVERSITY OF PETROLEUM & MINERALSCOLLEGE OF COMPUTER SCIENCES & ENGINEERING

Department of Systems Engineering

SE 207MODELLING AND SIMULATION

LAB MANUAL

Term 061

KING FAHD UNIVERSITY OF PETROLEUM & MINERALSSystems Engineering Department

SE 207 MODELLING AND SIMULATION

Laboratory Objective

Emphasize the practical aspects of the course and enable each student to:

Simulate systems described by ODE, Input-output models and state variable models

using

o Comdyna GP6 analog computers

o MATLAB and SIMULINK

Be familiar with equipment needed such as function generator, multimeters, oscilloscope,

To simulate and observe behavior of first and second order systems.

Table of ContentsLaboratory Objective.......................................................................................................................2EXPERIMENT #1: Introduction to Analog Computers..................................................................4Review of Solutions of Linear Ordinary Differential Equations...................................................11EXPERIMENT # 2: Basic Operations of the Analog Computer.................................................13EXPERIMENT # 3: Analog Simulation of a First Order System (RC Circuit)............................16EXPERIMENT # 4: Analog Simulation of a Second Order Mass-Spring Mechanical System. . .18Experiment #5: Function Generation Using the Analog Computer.............................................20Experiment #6:Analog Simulation of a System of Coupled Masses.............................................22Experiment 7 : Introduction to Digital Computer Simulation (MATLAB & SIMULINK)..........24Experiment 8 : MATLAB m-files and their use in system simulation..........................................31Experiment # 9 :Simulation of systems having relative displacements with other moving body33Experiment # 10: Simulation of systems represented by state variable model............................36

EXPERIMENT #1: Introduction to Analog Computers

Objective: Introduction to Analog Computers and its operation

Introduction

The analog computers were the first computer devices invented. They were heavily used during the Second World War to predict the trajectories of bombs and shells and to solve stiff differential equations. They are still used today in instrumentation, A/D-D/A converters, navigation systems and other areas where they offer advantages over the digital computer. An analog computer is nothing but an electric circuit that is configured to mimic the behavior of a differential equation. The computer solves the problem by solving a corresponding problem patched on the computer. Most general purpose analog computers use an active electrical circuit as the analogous system because it has no moving parts, a high speed of operation, good accuracy, and a high degree of versatility. Active electrical networks consisting of resistors, capacitors, and operational amplifiers (OP amps) connected together are capable of simulating any linear system since the forward voltage transfer characteristics of these networks are analogous to the basic linear mathematical operations that are applied in the system’s model. Also, by using diode function generators and special circuits which have nonlinear voltage transfer characteristics, it is possible to simulate nonlinear systems. The mathematical model of an analog computer programmed to simulate a specific system is identical to the mathematical model of the system. The voltage transfer characteristics of the electrical networks are analogous to the desired mathematical operations. The input and output voltages (computer variables) are equivalent to the corresponding mathematical variables (problem variables) of the problem. Because of limitations of the computer or its associated input/output equipment, it is usually necessary to change the scale of the computer variables, thus forcing the values of a computer variable to differ from the corresponding problem variable values. It is important to understand that an analog computer solution is simply a voltage waveform whose time dependency is the same as that of the desired variable.

The normal procedure for simulating a system starts with determining the mathematical model describing the physical quantities of interest. An analog block diagram is made to relate the sequence of mathematical operations and to aid in scaling the variables. From the analog block diagram, the electrical components are connected together (patched). The computer is operated and the computer variables observed on a recorder or oscilloscope. Since the output is a computer variable (voltage waveform) it is necessary to convert the output variable back to the original problem variable.

The COMDYNA, GP-6 Analog ComputerIn this laboratory course, we will be using the COMDYNA, GP-6 Analog computers that are available in the Systems Engineering Department. The GP-6 is a general purpose analog computer. It contains linear and .nonlinear components. The linear part contains panels for summers, integrators, inverters and attenuators; while the nonlinear part contains multipliers,

square-root generators and other components. The GP-6 has a linear range of +10 to -10 volts shown as +1 to -1 unit on the display panel.

The GP-6 offers hands-on analog experiments to introduce the concepts of systems, mathematical modeling and simulation, the application of and programming of linear circuit device; Instrumentation/ Control circuitry and scaling of measured and control variables. Each GP-6 can simulate mathematical models of up to four, state variables. The following are some of the important features of the GP-6

Internal Components

1. Operational Amplifiers2. Summer Resistor Network3. Inverter Networks4. Electronic Switch Networks5. Integrator Capacitor sets6. Coefficient potentiometers7. Multipliers/divider Boards

Patch Panel

The traditional analog computer patch panel is the only means to program linear circuit devices. The GP-6 color coded panel is large and readily understood. Analog programming symbols clearly indicate the active devices and associated networks. Internal summing resistors, integrating capacitors, and active auxiliary circuits reduce patching connections without sacrificing flexibility. Standard banana jacks and plugs allow easy connection of external accessories, amplifiers, readout instrumentation, etc.

Interconnections

The GP-6 directly interconnects with all forms of analog, analog/digital and digital/analog instrumentation. Front panel banana jacks on the standard 3/4 inch spacing encourage patch cord connections as inputs and outputs.

The system positive/negative volts offers a precision reference available for external transducers, position potentiometers, etc.

Extras

Many extras aid operator convenience and laboratory usability. Extras include: time scales per integrator, time base ramp, compute-time readout, slavability.

Let us look more closely at the patch panel of the GP-6 and describe the function of each button and knob. A typical GP-6 has the following:

Control Switches

IC: Initial condition mode (push button type); is used to set the output of the integrators to the required initial condition.

Hd: Hold mode (push button type); is used to hold the variables to their current values.Op: Operate mode (push button type); is used to start the operation of the analog computer (integrators).RQ: Repetitive mode (push button type); is used to periodically set the mode into IC and OP. Coefficient Potentiometers l-8) (Rotary type); used to divide voltages for analog operation.Y/Pot address (Rotary type); used to set the potentiometer attenuation and to read the potentiometer voltage in the OP mode.X address (Rotary type); used to read and plot the Op amp. outputs.Mode selector (Rotary type); used to read potentiometer voltage, OP amp. output or external voltage.Compute time (Rotary type); used to generate ramp signals for the x-axis of the plotter. It contains the power switch.Overload Indicator used to indicate over voltage when an amplifier output exceeds 10.5 volts. It lights to indicate this, and will remain lit until the cause of the over voltage is removed.

MODES OF OPERATION

Manual operation: Press the push buttons IC for initial condition, Hd for holding the solution and OP to start a solution.

Repetitive operation: (RO): In this mode, the timer of the analog computer produces repetitive control signal that repetitively sets the integrators to initial condition and then in the operation mode.

COMPUTING COMPONENTS

Summers Two summers are available on the GP-6 analog computers. Each one consists of an operational amplifier and five resistors (three l unit resistors and two 0.1 unit resistors). In addition, any of the four integrators may also be used as summers.

Review of Solutions of Linear Ordinary Differential Equations

Since the analog computer deals mainly with linear or nonlinear differential equations describing the behaviors of some physical systems, it is very important that the student remembers some fundamental results in the solution of differential equations that he learned in his freshman. Therefore, we will devote this small section of this manual to review some of these results. However, the student is also expected to review these from some good books (reference [1] is a good source).

First order Equations

A linear first order equation with constant coefficient can be written as

(1)

where y(t) is the output of the system with initial value . f(t) is the input, which is a given time function, and , are constant coefficient. The solution to the above system (1) is comprised of two parts. A complementary solution (CS), and a particular solution (PS). The complementary solution is the solution of the system when the input function f(t) = 0. It is also referred to as the zero input solution. Furthermore, it governs the transient response of the system. To get the complementary solution of the above system, we first obtain the auxiliary equation of the system which is given by

(2)

in terms of the auxiliary variable. The solution (root) of this ordinary equation gives the system mode (or time constants), and in this case is given by

(3)

Finally, we can now write the complementary solution as

(4)

where C is an arbitrary constant to be determined from the initial conditions. For the case of the first order system, . Therefore, the solution becomes

(5)

Now regarding the particular solution of the system, this depends on the input function f(t). The particular solution also determines the steady state behavior of the solution. Also, there are various methods of obtaining it. Some of these methods are : the method of integrating functions; the method of variation of parameters; the method of undetermined coefficients and the Laplace transform method (see reference j1 for more details on this). The Laplace transform method is

probably the easiest for the student. It also has the advantage of giving both the complementary solution (CS) and the particular solution (PS). The sum of these two solutions gives the whole solution of the system.

Second order EquationsA second order equation can similarly be represented as

(6)

Without any lost of generality, we can divide the above equation throughout by a and write the system as

(7)

where , , g(t) are the corresponding coefficients and input respectively.

To find the complementary solution to the above system, we find the auxiliary equation of the system as in the first order case. This is given by

(8)

Let the roots of this quadratic equation be OC ,a Then the complementary solution of the above system is given by

(9)

where , are constants, to be determined from the initial conditions. The equation (9) is the general form of the complementary solution. If however, the roots are complex conjugates, then equation (9) can further be simplified in the following way:

Let the roots be in this case

(10)

Then the complementary solution is given by

(11)

where , are another set of arbitrary constants to be determined from the initial conditions.

Finally, the particular solution of the second order equation can also be determined using Laplace transform method.

Reference[1] E. W. Kryszig, Advanced Engineering Mathematics, Wiley International Edition, 1992.

EXPERIMENT # 2: Basic Operations of the Analog Computer

OBJECTIVES:

The objective of this experiment is to learn basic analog computer operations, namely, summing and integration operations.

INTRODUCTION

The operation of summation of two quantities (signals) can be performed using the analog computer connected as a summer. This is essentially an Op amp. with a resistor in the feedback path (the feedback resistor) and two resistors connected in the forward path through which the signals are summed. Similarly, an integration of a signal can be performed with the analog computer by connecting it as an integrator. In this case, a capacitor is connected in the feedback path and a resistor in the forward path. Moreover, a number of signals can be integrated at the same time and the sum of their integrals be taken using a summing integrator.

EQUIPMENT:

GP-6 Analog computer with power supply and connecting wires.

BACKGROUND

The operation of summation of any number of input voltages, say, E1, E2, …En is given by the output voltage:

(1)

where Rf is the feedback resistor in the summer configuration and R1,R2, . . . , Rn are the resistors in the forward path. The minus sign appearing in the expression (1), is due to the inversion of the signals by the OP amp. in the inverting configuration. Fig. 1. shows how the summer is connected.

Similarly, an integration operation results in the following output voltage

(2)

where E is the input voltage, R is the value of the resistor in the forward path and C is the value of the capacitor in the feedback path. For n input voltages, E1,E2,..,En connected through n resistors R1,R2,..,Rn the sum of their integrals is given by the output voltage:

(3)

Finally, the operation of the summing integrator and how it is connected are also shown in Fig. 2.

PROCEDURE:

1. To verify Summing Operation

(i) Turn on the power ON switch using the COMPUTE TIME knob.(ii) Check to see that all Op amps. (six of them) are connected either through a resistor or a capacitor in the feedback path.(iii) Now Connect the summing amplifier as shown in Fig: 1(a).(iv) To set the potentiometers, set the Mode selector to Pot set and select the desired potentiometer from the Y/pot address. Now connect the potentiometer input to the supply and adjust its setting using the corresponding potentiometer knob and the display. While you are doing this, check the rear of the panel to make sure that the meter is connected to the Y/address.(v) Complete the connections for the summing amplifier as shown in Fig. 2. (Patch panel operation). Once you are finished with the connections, call the instructor to check it for you and make sure that it is correct.(vi) Now monitor the output of the summer on the display panel and record the result. To do this, set the Y/pot address to GND/X and the X/address to the desired amplifier (1-6). Set the Mode selector to OPR and press the OP push button. Also check the rear of the GP-6 to see that the X-address is connected to the meter.

11 .To verify Integrator Operation

(i) Similarly, connect the integrator as shown in Fig. 1(b) to generate a ramp.(ii) Increase the compute time to 100 using the compute-time knob. This allows the integrator to integrate slowly.(iii) Now monitor the output of the corresponding amplifier on the display panel, and see that it overloads after a short time. This confirms that the output of the amplifier is the integral of the input, and reaches the maximum value of 10 volts as the input is being summed.

Report

Your report should include the following:

1. The theoretical results of the summing operation i.e. calculate the actual output of the summer from the given input voltages. Compare this result with the one obtained in the experiment.

2. Calculate also the theoretical value of the output of the integrator after the elapse compute time (100s). Compare this with the value obtained in the experiment when the amplifier saturates.

3. Finally, draw conclusions from (a) and (b) above. Have the objectives of the experiment been achieved?

Figure 1: A Summer with Four inputs

Figure 2 An Integrator with one input

0.011

1

10

10

Eo(t)

0.02

0.02

0.01

E1(t)=-10 V

E2(t)=+10 V

E3(t)=+10 V

E4(t)=-10 V

0.05E(t)=+10 V

1 Eo(t)

EXPERIMENT # 3: Analog Simulation of a First Order System (RC Circuit)

OBJECTIVES:

The objective of this experiment is to simulate a first order system, an RC-circuit, and study its behavior.

INTRODUCTION

An electrical RC-circuit is the simplest example of a first order system. It comprises of a resistor and capacitor connected in series to a voltage supply as shown below on Figure 1. If the capacitor is initially uncharged at zero voltage when the circuit is switched on, it starts to charge due to the current i through the resistor until the voltage across it reaches the supply voltage. As soon as this happens, the current stops flowing or decays to zero, and the circuit becomes like an open circuit. However, if the supply voltage is removed, and the circuit Is closed, the capacitor will discharge the energy it stored again through the resistor. The time it takes the capacitor to charge depends on the time constant of the system, which is defined as the time taken by the voltage across the capacitor to rise to approximately 63% of the supply voltage. For a given RC-circuit, this time constant is . Hence its magnitude depends on the values of the circuit components.

The RC circuit will always behave in this way, no matter what the values of the components. That is, the voltage across the capacitor will never increase indefinitely. In this respect we will say that the system is passive and because of this property it is stable.

EQUIPMENT:

1. GP-6 Analog Computer2. X-Y Plotter

BACKGROUND

For the RC-circuit as shown in Fig. 1, the equation governing its behavior is given by

(1)

where is the voltage across the capacitor, R is the resistance and C is the capacitance. The constant is the time constant of the system and is defined as the time required by the system output i.e. to rise to 63% of its final value (which is E). Hence the above equation (1) can be expressed in terms of the time constant as:

(1)

PROCEDURE

(1) First write the system equations in the form suitable for drawing the analog simulation diagram.(ii) Now draw the analog block diagrams corresponding to the following values of R, C, and E:given in Table 1.

Table 1 E=1.0 volts,

Time R C10 sec 1 0.220 sec 1 0.1

(iii) For the first set of values, connect the analog circuit on the GP-6 using one integrator. (iv) Set the Y/pot-address to GND/X and mode selector to OPR.(v) Select the output amplifier from the X-address, press the OP push button and monitor the output of the output of the system v(vi) Repeat the above procedure (iv) and plot the output of the system on the X-Y plot. The procedure of how to operate the X-Y plotter is explained in the attached sheet.(vii) Now repeat the above procedures (i)-(vi) for the second set of values of R, C.

REPORT

Your report should include the following:(i) A plot of the capacitor output voltage for the two cases.(ii) From the plots, estimate the time-constant of the system.(iii) Compare the experimental values of the time-constant with the theoretical values

from Table 1.(iv)Give comments and conclusion on your observations.

EXPERIMENT # 4: Analog Simulation of a Second Order Mass-Spring Mechanical System

OBJECTIVES:

The objective of this experiment is to simulate a second order mass-spring system and study its behavior.

INTRODUCTION

The mass spring system is a very good example of a second order physical system. The equations governing the behavior of the system are easily derived from Newton’s law. Indeed all mechanical systems, right from the simple pendulum to the more complicated aircraft are of second order form; because of the fact that they obey Newton’s laws or Lagrange’s or Hamilton’s principle. Therefore, studying the behavior of the mass-spring system, will give us great insight into the behavior of many. mechanical systems without too much complicated mathematical analysis.Furthermore, because of the frictional effects on the system, and an additional damping that may be introduced in the system, the mass-spring system is always a stable system. That is, it represents an energy dissipative system.

EQUIPMENT :

1. GP-6 Analog Computer2. X-Y Plotter

BACKGROUND

The mass-spring system is shown in Fig.1, the equation governing its behavior is given by

where f is the input force, x is the displacement, M is the mass of the system, B is friction and K is the spring constant.

PROCEDURE

(i) First write the system equations in the form suitable for drawing the analog simulation diagram.(ii) Now draw the analog block diagrams corresponding to the following values of M, B, and K:given in Table 1.(iii) For the first set of values, connect the analog circuit on the GP-6 using two integrator. (iv) Set the Y/pot-address to GND/X and mode selector to OPR.(v) Select the output amplifier from the X-address, press the OP push button and monitor the output of the output of the system x(t).(vi) Plot the response of the system on the X-Y plotter. Details of how to use the X-Y plotter are attached.

(vii) Now repeat the above procedures (i)-(vi) for the remaining set of values of M B, K.Table 1.

T (secs) M B K10 1 0 2 0 010 1 1 2 2 010 1 2 2 1 110 1 3 2 0 0

REPORT

Your report should include the following:(i) A plot of the response (displacement x(t)) for the various values of the parameters.(ii) Compare the response of the system for the various values of the parameters and make

comments.(iii) For what set of values of the parameters does the system has the fastest response?(iv)For what set of values of the parameters does the system has the slowest response?(v) For what set of values of the parameters is the system oscillatory? Can you explain why?(vi)Give comments and conclusions on your observations.

Figure 1: Mass-Spring-friction System

M

x

f(t)K

B

Experiment #5: Function Generation Using the Analog Computer

OBJECTIVES

The objective of this experiment is to synthesize a number of time functions (signals) using the analog computer.

INTRODUCTION

The analog computer can be utilized to generate the various functions or waveforms e.g. sinusoidal signal, saw-tooth, square waveform etc. which are used in various applications. These signals can be synthesized as outputs of linear differential equations whose solutions are the required function.

Therefore, the first step in synthesizing such time functions, is to recover the differential equation governing its behavior. There are many ways to get this differential equation. The simplest way is to write the solution of the differential equation in terms of the required time function and to walk back to the differential equation by differentiation. It is also important here to keep track of the initial condition. Another approach is to represent the input and output of the differential equation corresponding to the required time function in the s-domain (using Laplace transforms) and to recover the differential equation by taking inverse Laplace transform. Yet one can also recover the differential equation from experience.

EQUIPMENT:

GP-6 Analog ComputerX-Y Plotter

BACKGROUND

The time functions we are interested in synthesizing are the following:(a) (b) (c) (d) where A, and are given constants.

PROCEDURE

(i) First write the obtain the differential equations whose solutions are the corresponding time functions.For example, for the first waveform (a), this can be obtained as follows. Let

x(t) = , which implies that x(0) = 0.Then

and And

Therefore, the required differential equation whose solution is the given time function is

(ii) Now draw the analog block diagram to simulate the above system and generate the required time function.(iii) Simulate the differential equation and plot its output using the X-Y plotter as explained in the previous experiments. The result should correspond with the desired time function.(iv) Repeat the above procedure (i)-(iii) for the time functions (b) and (c). The following Hint will also help you for the case of the time function (iv).

Hint: Functions (a) and (b) require identical unforced second-order differential equations with initial conditions. Function (c) requires a first order unforced differential equation, and function (d) requires a first order differential equation having the forcing function given by (c). Alternatively, you can generate (d) from a second order linear differential equation with constant coefficients whose auxiliary equation has equal roots. Please refer to the introductory part of this manual on linear differential equations.

REPORT

Your report should include the following:(i) The analog simulation diagrams with labels.(ii) A plot of the response of the simulations for all the time functions.(iii) Compare these plots with the actual time functions and make comments.(iv) Give comments and conclusions on your observations.

Exercise

(i) For the time function (a), if you increase A, and separately, what happens to the output of the analog computer?(ii) Similarly, for the time function (c), if you increase , what happens to the output of the analog computer?

Experiment #6: Analog Simulation of a System of Coupled Masses

OBJECTIVES

The objective of this experiment is to study the behavior of a system of coupled mass-spring systems using the analog computer.

INTRODUCTION

Many engineering systems have more than one input and more than one output. For example, an aircraft has as its outputs its horizontal speed, its vertical speed and its altitude; a 6 degree of freedom robot manipulator has as its output three Euler Angles and three spatial coordinates of its end effector (Px, Py, Pz); while it has as inputs as many as six joint torques. Such systems are called multiple-input, multiple- output systems (MIMO, or in short multivariable systems). Furthermore, the system may also be large, in which case, it may present a lot of difficulties in modeling and simulation. One approach may be to divide the system into smaller subsystems and study the behavior of each subsystem separately. This approach works very well if the interaction between the subsystems is small and can always be predicted. The overall behavior of the system can then be studied by combining the behavior of the subsystems:Another alternative, is to study the effect of each input on the overall system outputs separately, and then sum up these effects for all the inputs to get the overall response of the system.It is therefore the purpose of this experiment, to introduce the student to the modeling and simulation of MIMO systems.

BACKGROUND

Figure 1. shows the model of the system. It is basically a two mass-spring system coupled side-by-side together. The equations governing the behavior of the system are given by:

where all the terms are explained in the previous experiment and in Figure 1. Note that the two

subsystems are coupled together by the terms , .

EQUIPMENT

(i) GP-6 Analog Computer(ii) X-Y Plotter

PROCEDURE

(i) Rewrite the dynamical equations governing the behavior of the system in the form suitable for simulation. For the values of parameters given in Table 1 below, draw the analog simulation block for the system.

Table 1. B3=1

M1 M2 B1 B2 k1 k2 f1 f2 T(sec)1 1 1 1 4 4 10 0 101 1 1 1 3 4 0 10 10

Now simulate the system for each set of values of the parameters and plot the response of the system for both x1, x2 , using the X-Y plotter as in the previous experiments.

(ii) Find analytically, x1(t) and x2(t) by assuming f1(t)=0 and f2(t) = 10u(t).

(iii) Find for this case, and

(iv) Compare the values you got in (iii) with the values you got from the simulation.

Report

In your report, include the following:(i) Free-body diagram for the different masses.(ii) Analog simulation diagrams with labels.(iii) Plots of the displacements of the variables x and x(iv)Discussion of results and conclusions.

Figure 1

Experiment 7 : Introduction to Digital Computer Simulation (MATLAB & SIMULINK)

INTRODUCTION

This lab introduces a powerful numerical simulation software, MATLAB and its graphical user interface (GUI), Simulink. This software is used for solving the modeling equations and obtaining the response of a system to different inputs. The software is run on digital computers. Both linear and nonlinear differential equations can be solved numerically with high precision and speed, allowing system responses to be calculated and displayed for many input functions. To provide an interface between a system’s modeling equations and the digital computer, block diagrams drawn from the system’s differential equations are used. A block diagram is an interconnection of blocks representing basic mathematical operations in such a way that the overall diagram is equivalent to the system’s mathematical model. The lines interconnecting the blocks represent the variables describing the system behavior. These may be inputs, outputs, state variables, or other related variables. The blocks represent operations or functions that use one or more of these variables to calculate other variables. Block diagrams can represent modeling equations in both input-output and state variable form.

We use MATLAB with its companion package Simulink, which provides a graphical user interface (GUI) for building system models and executing the simulation. These models are constructed by drawing block diagrams representing the algebraic and differential equations that describe the system behavior. The operations that we generally use in block diagrams are summation, gain, and integration. Other blocks, including nonlinear elements such as multiplication, square root, exponential, logarithmic, and other functions, are available. Provisions are also included for supplying input functions, using a signal generator block, constants etc and for displaying results, using a scope block.An important feature of a numerical simulation is the ease with which parameters can be varied and the results observed directly. MATLAB is used in a supporting role to initialize parameter values and to produce plots of the system response. Also MATLAB is used for multiple runs for varying system parameter-s. Only a small subset of the functions of MATLAB will be considered during these labs.

SIMULINK

Simulink provides access to an extensive set of blocks that accomplish a wide range of functions useful for the simulation and analysis of dynamic systems. The blocks are grouped into libraries, by general classes of functions.

• Mathematical functions such as summers and gains are in the Math library.• Integrators are in the Continuous library.• Constants, common input functions, and clock can all be found in the Sources library.• Scope, To Workspace blocks can be found in the Sinks library.

Simulink is a graphical interface that allows the user to create programs that are actually run in MATLAB. When these programs run, they create arrays of the variables defined in Simulink that can be made available to MATLAB for analysis and/or plotting. The variables to be used in MATLAB must be identified by Simulink using a To Workspace block, which is found in the Sinks library. (When using this block, open its dialog box and specify that the save format should

be Matrix, rather than the default, which is called Structure.) The Sinks library also contains a Scope, which allows variables to be displayed as the simulated system responds to an input. This is most useful when studying responses to repetitive inputs.

Simulink uses blocks to write a program. Blocks are arranged in various libraries according to their functions. Properties of the blocks and the values can be changed in the associated dialog boxes. Some of the blocks are given below.

SUM (Math library)A dialog box obtained by double-clicking on the SUM block performs the configuration of the SUM block, allowing any number of inputs and the sign of each. The sum block can be represented in two ways in Simulink, by a circle or by a rectangle. Both choices are shown

Figure 1: Two Simulink blocks for a summer representing y = x 1+ x2 – x3

GAIN (Math library)A gain block is shown by a triangular symbol, with the gain expression written inside if it will fit. If not, the symbol - k - is used. The value used in each gain block is established in a dialog box that appears if the user double-clicks on its block.

Figure 2: Simulink block for a gain of K.

INTEGRATOR (Continuous library)The block for an integrator as shown below looks unusual. The quantity 1/s comes from the Laplace transform expression for integration. When double-clicked on the symbol for an integrator, a dialog box appears allowing the initial condition for that integrator to be specified. It may be implicit, and not shown on the block, as in Figure (a). Alternatively, a second input to the block can be displayed to supply the initial condition explicitly, as in part (b) of Figure 3. Initial conditions may be specific numerical values, literal variables, or algebraic expressions.

X1

X2

X3

X1

X2

X3

Figure3: Two forms of the Simulink block for an integrator.(a) Implicit initial condition. (b) Explicit initial condition.

CONSTANTS (Source library)Constants are created by the Constant block, which closely resembles Figure 4. Double- clicking on the symbol opens a dialog box to establish the constant’s value. It can be a number or an algebraic expression using constants whose values are defined in the workspace and are therefore known to MATLAB.

Figure 4: A constant block

STEP (Source library)A Simulink block is provided for a Step input, a signal that changes (usually from zero) to a specified new, constant level at a specified time. These levels and time can be specified through the dialog box, obtained by double-clicking on the Step block.

Figure 5: A step block

SIGNAL GENERATOR (Source library)One source of repetitive signals in Simulink is called the Signal Generator. Double-clicking on the Signal Generator block opens a dialog box, where a sine wave, a square wave, a ramp (sawtooth), or a random waveform can be chosen. In addition, the amplitude and frequency of the signal may be specified. The signals produced have a mean value of zero. The repetition frequency can be given in Hertz (Hz), which is the same as cycles per second, or in radians/second.

Figure 6: A signal generator block

SCOPE (Sinks library)The system response can be examined graphically, as the simulation runs, using the Scope block in the sinks library. This name is derived from the electronic instrument, oscilloscope, which performs a similar function with electronic signals. Any of the variables in a Simulink diagram can be connected to the Scope block, and when the simulation is started, that variable is displayed. It is possible to include several Scope blocks. Also it is possible to display several

signals in the same scope block using a MTJX block in the signals & systems library. The Scope normally chooses its scales automatically to best display the data.

Figure 7: A scope block with MUX block

Two additional blocks will be needed if we wish to use MATLAB to plot the responses versus time. These are the Clock and the To Workspace blocks.

CLOCK (Sources library)The clock produces the variable “time” that is associated with the integrators as MATLAB calculates a numerical (digital) solution to a model of a continuous system. The result is a string of sample values of each of the output variables. These samples are not necessarily at uniform time increments, so it is necessary to have the variable “time” that contains the time corresponding to each sample point. Then MATLAB can make plots versus “time.” The clock output could be given any arbitrary name; we use “t” in most of the cases.

Figure 8: A clock block

To Workspace (Sinks library)The To Workspace block is used to return the results of a simulation to the MATLAB workspace, where they can be analyzed and/or plotted. Any variable in a Simulink diagram can be connected to a ToWorkspace block. In our exercises, all of the state variables and the input variables are usually returned to the workspace. In addition, the result of any output equation that may be simulated would usually be sent to the workspace. In the block parameters drop down window, change the save format to ‘array’.

Figure 9: A To Workspace block

In the Simulink diagram, the appearance of a block can be changed by changing the foreground or background colours, or by drop shadow or other options available in the format drop down menu. The available options can be reached in the Simulink window by highlighting the block, then clicking the right mouse button. The Show Drop Shadow option is on the format drop-down menu.Simulink provides scores of other blocks with different functions.You are encouraged to browse the Simulink libraries and consult the online Help facility provided with MATLAB.

GENERAL INSTRUCTIONS FOR WRITING A SIMULINK PROGRAM

To create a simulation in Simulink, follow the steps:• Start MATLAB.• Start Simulink.• Open the libraries that contain the blocks you will need. These usually will include the

Sources, Sinks, Math and Continuous libraries, and possibly others.• Open a new Simulink window.• Drag the needed blocks from their library folders to that window. The Math library, for

example, contains the Gain and Sum blocks.• Arrange these blocks in an orderly way corresponding to the equations to be solved.• Interconnect the blocks by dragging the cursor from the output of one block to the input

of another block. Interconnecting branches can be made by right-clicking on an existing branch.

• Double-click on any block having parameters that must be established, and set these parameters. For example, the gain of all Gain blocks must be set. The number and signs of the inputs to a Sum block must be established. The parameters of any source blocks should also be set in this way.

• It is necessary to specify a stop time for the solution. This is done by clicking on the Simulation > Parameters entry on the Simulink toolbar.

At the Simulation > Parameters entry, several parameters can be selected in this dialog box, but the default values of all of them should be adequate for almost all of the exercises. If the response before time zero is needed, it can be obtained by setting the Start time to a negative value. It may be necessary in some problems to reduce the maximum integration step size used by the numerical algorithm. If the plots of the results of a simulation appear “choppy” or composed of straight-line segments when they should be smooth, reducing the max step size permitted can solve this problem.

ADDITIONAL INSTRUCTIONS FOR MATLAB PLOTSIn order to be able to produce MATLAB plots versus time, the output of a Clock block must be sent to MATLAB by using a To Workspace block. The variables of interest must also be sent to MATLAB. The plots and its associated commands must be entered in the MATLAB command window (main MATLAB window). Some of the commands are given below.

helpThis command followed by the command for which help is needed can be used to get help on any of the MATLAB commands. E.g. help plot on the command window will display help for plot command.

plot(t,x)Plots the time versus variable x. Time axis is the x-axis, while the variable x is plotted on y axis. Other plot related commands are xlabel, ylabel, title, gtext, text, grid, axis. and subplot.

hold onHolds the plot for further values to be plotted on the same plot. Useful when multiple runs are made using varying parameter values and a single plot is required for comparison purposes. hold off releases the plot.

EXERCISE 1: Modeling of a second order system

Construct a Simulink diagram to calculate the response of the Mass-Spring system shown below. The input force increases from 0 to 8 N at t = 1 s. The parameter values are M 2 kg, K= 16 N/m, and B =4 N.s/m.

PROCEDURE:

• Draw the free body diagram• Write the modeling equation from the free body diagram• Solve the equations for the highest derivative of the output.• Draw a block diagram to represent this equation.• Draw the corresponding Simulink diagram.• Use Step block to provide the input fa(t).• In the Step block, set the initial and final values and the time at which the step occurs.• Use the To Workspace blocks for t, fa(t), x, and v in order to allow MATLAB to plot the

desired responses. Set the save format to array in block parameters.• Select the duration of the simulation to be 10 seconds from the Simulation > Parameters

entry on the toolbar• Run the simulation by clicking the Start button.

When the computer makes a short chirp sound, the simulation is complete, and the variables that have been sent to the workspace are available there for analysis and/or plotting.

• To get the plots, enter the command plot (t, x) in the main MATLAB window.Several functions are available to make plots more informative. Among these are: xlabel, ylabel, title, gtext, text, grid, axis and subplot.

• Use xlabel, ylabel and title to label your graphs

USE help command on the MATLAB command window to get help on any command.

EXERCISE 2: System response from the stored energy with zero input

Find the response of the above system when there is no input for t ≥0, but when the initial value of the displacement x(0) is zero and the initial velocity v(0) is 1 m/s.

PROCEDURE:In the previous program• Set the size of the input step to zero• Set the initial condition on Integrator for velocity to 1.0.• Plot the results.

EXERCISE 3: Simulation with system parameter variation

The effect of changing B is to alter the amount of overshoot or undershoot. These are related to a term called the damping ratio. Simulate and compare the results of the variations in B in exercise 1. Take values of B = 4, 8, 12, 25 N-s/m.

PROCEDURE:

Perform the following steps. Use the same input force as in Exercise 1.• Begin the simulation with B = 4 N-s/m, but with the input applied at t 0• Plot the result.• Rerun it with B = 8 N.s/m.• Hold the first plot active, by the command hold on• Reissue the plot command plot(t,x), the second plot will superimpose on the first.• Repeat for B = 12 N-s/m and for B = 25 N-s/m• Release the plot by the command hold off• Show your result.

EXERCISE 4: Response for a sinusoidal input

Prepare a Simulink implementation of the system with the same values as in Exercise 1, Use it to simulate and plot the response to the sinusoidal input

where This specified input is a sinusoid having an amplitude of 8 N (16 N peak—to-peak) and a frequency of 0.05 Hz. The period is 1/ (0.05) = 20 s.Plot the response for the interval 0≤ t ≤ 50S.

PROCEDURE:

• Use the same Simulink program as in Exercise 1• Replace the Step input by the Signal Generator• Set the Signal Generator to produce sine waves of amplitude 8, frequency 0.05 Hz• Plot the input and the response

REPORT:

Copy of your programsResults of the programsComments on the resultsComparison of results with analytical values where possible

Experiment 8: MATLAB m-files and their use in system simulation.

MATLAB functionalities are exploited for running simulations for systems having varying parameters. The parameter variation is also used during the designing stage of a system, when the system responses are checked under varying conditions. MATLAB m-files are introduced to save and rerun the work done on MATLAB command window. Models created in Simulink can be executed in MATLAB command window or alternately by using an m-file.

Programming in MATLAB using M-filesMATLAB has a feature called M-files that can simplify its operational use. These are flies containing MATLAB statements, which can be saved and re-executed by a single MATLAB command. Three types of statements are particularly useful with Simulink.

• The values of the parameters of a model can be saved in an M-file and changed by editing this file if needed.

• Commands to execute a model can be included, so that the results of a simulation are created.

• Plot commands and other post simulation data analysis and display commands can be used to cause the production, printing, or storage of the desired product.

M-files are produced with a text editor; there is one built into MATLAB that is accessible from the toolbar or through the edit command.

The Simulink model for a mass-spring system, shown below, was developed in the last experiment. This model is used as a reference in this experiment to develop the understanding in programming MATLAB m-files.

Modify the program by writing the variables M, K and B in place of the values in the Simulink model. Save the model as exlmodel.mdl (You can use any other name but then use the same name in all the following m-files).

Loading variable values through MATLAB:Simulink programs are run in MATLAB command window, even if executed by the run button in the Simulink window. So if the variables are defined in MATLAB and then Simulink program is executed, the Simulink program will take the variable values from the MATLAB command window.

Given below is a file that will set up the MATLAB workspace by establishing the values of the parameters needed for the Simulink simulation of the given model.

M-file for parameter values% This file is named exl_parameter.m.% Everything after a % sign on a line is a comment that% is ignored by M This file establishes the% parameter values for exl_model.mdl.%M2; %kgK= 16; %N/mB=4; % Ns/m

Plotting the outputs in MATLAB:The file to create the plots of the output is given below. Create the file and save it by the name given below.

M-file to produce the plot% This file is named exl_plot.m.% It makes a plot of the data produced by exl_model.mdl.plot(t,x); grid % Plots x for the case with B=4. xlabel(’Time (s)’);ylabel (‘Displacement (m) ')

A semicolon in a physical line ends the logical line, and anything after it is treated as if it were on a new physical line. A semicolon at the end of a line that generates output to the command window suppresses the printing of that output.

Program Execution:Follow the following steps to execute these files:

• Enter the command exlparameter in the command window. This will load the parameter values of the model.

• Open the Simulink model exl_model.mdl and start the simulation by clicking on the toolbar entry Simulation> Start.

• Enter the command exl_ plot in the command window to make the plot.

Making Subplots in MATLAB:When two or more variables are being studied simultaneously, it is frequently desirable to plot them one above the other on separate axes, as can be done for displacement and velocity in. This is accomplished with the subplot command. The following M-file uses this command to produce both plots of displacement and velocity.

M-flle to make subplots% This file is named exlplot2.m.% It makes both plots, displacement and velocity.% Execute exlparameter.m first. subplot(2,l,1);plot(t,x); grid % Plots x for the case with B=4. xlabel (‘Time (s) ‘) ;ylabel (‘Displacement (m) ‘); subplot(2,1,2);plot(t,v); grid % Plots v for the case with B=4. xlabel(’Time (s)’);ylabel(’Velocity (mis)’);

Multiple runs in MATLAB:If a complex plot is desired, in which several runs are needed with different parameters, this can all be accomplished by executing ex1_model (to load parameters) followed by this M-file. Entering the command ex1_plots in the command window results in multiple runs with varying values if B and will plot the results.

M-file to produce multiple runs and their plots% This file is named exl_plots.m.% It plots the data produced by exl_model.mdl for% several values of B. Execute exl_parameter.m first.sim(’exl_model’) % Has the same effect as clicking on

% Start on the toolbar.plot(t,x) % Plots the initial run with B=4hold on % Plots later results on the same axes % as the first.B = 8; % New value of B; other parameter values % stay the same.sim(exl_model % Rerun the simulation with new B value.plot(t,x) % Plots new x on original axes.B 12; sim(’exl_model’);plot(t,x)B = 25; sim(’exl_model’ ) ;plot(t,x)hold off

REPORT:

Copy of your programsResults of the programsComments on the resultsComparison of results with analytical values where possible

Experiment # 9: Simulation of systems having relative displacements with other moving body

INTRODUCTION

In a linear translational system such as the two-mass system shown below in the figure, the displacement variable associated with each mass can be expressed with respect to a fixed reference position. However, sometimes the position of a mass is measured with respect to some other moving object rather than a fixed point. This is known as relative displacement.

Let x denote the position of mass M1 with respect to fixed reference point and z denote the relative displacement of mass M2 with respect to mass M1. The positive direction for both displacements is towards right. The two springs are neither stretched nor compressed when x=z=0.

PROCEDURE:

• Draw the free body diagram for the two-mass system• Write the modeling equation describing the system from the free body diagram• Compare the equations with the equations given below

• Solve the equations for the highest derivative of the output.• Draw the corresponding Simulink diagram.• Use the To Workspace blocks for t, fa(t), x, and z in order to allow MATLAB to plot the desired responses. Set the save format to array in block parameters.

EXERCISE 1:

Plot the first 10 seconds of the response when the applied force fa(t) increases from 0 to 100 N at t= 1sec.. The parameter values are: M1 = M2 = 5 kg, B1 = B2= 20 N.s/m, B3=50N.s/m, and K1 = K2 = 100 N/m. Plot both x and z on the same axes.PROCEDURE:

• Use Step block to provide the input fa(t).

z

x

K2

K1

M1

M2

B1

B2

B3

Fa(t)

• In the Step block, set the initial and final values and the time of step when it occurs.• Select the duration of the simulation to be 10 seconds from the Simulation > Parameters

entry on the toolbar• Write an m-file setting the system parameters,• Include system execution commands in the m-file• Also include plotting statements in the same m-file.• Run the simulation in MATLAB command window and show your work.

EXERCISE 2:

From exercise 1, change the values of B2 =30 N.s/m and B3 =20 N.s/m and K1 =20 N/m.Rerun the simulation and compare the responses.

PROCEDURE:

• Make modifications in your m-file to change the parameters given above.• Run your simulation again• Compare the results of Exercise 1 and 2 and comment on its physical interpretation.

EXERCISE 3:

Repeat Exercise 1 when the displacement of each mass is expressed with respect to its own fixed reference position. Let x1 and x2 denote the displacements of M1 and M2 respectively with the positive senses to the right.

PROCEDURE:

• Draw the free body diagram for the two-mass system• Write the modeling equation describing the system from the free body diagram• Compare the equations with the equations given below

• Solve the equations for the highest derivative of the output.• Draw the corresponding Simulink diagram.• Use the To Workspace blocks for t, fa(t), x1, and x2 in order to allow MATLAB to plot the

desired responses. Set the save format to array in block parameters.• Now use the procedure of Exercise 1 to run the simulation• Comment on the output and compare with the output of Exercise 1.

Experiment # 10: Simulation of systems represented by state variable model

INTRODUCTION

In a linear translational system such as the two-mass system shown below in the figure, the state variables are the displacements and the velocities of the two masses.

Let x1 and v1 denote the position and velocity of mass M1 with respect to fixed reference point and x2 and v2 denote the position and velocity of mass M2. The positive direction for both displacements is towards right. The two springs are neither stretched nor compressed when x1 = x2 =0.

PROCEDURE:

• Draw the free body diagram for the two-mass system• Write the modeling equation in state variable form describing the system from thefree body diagram• Compare the equations with the equations given below

• Draw the corresponding Simulink diagram.• Use the To Workspace blocks for t, fa(t), x1, and x2 in order to allow MATLAB to plot the desired responses. Set the save format to array in block parameters.

EXERCISE 1:

Plot the first 10 seconds of the response when the applied force fa(t) increases from 0 to 10 Nat t= 1 sec. The parameter values are: M1 = M2 =10 kg, B1 = B2= B3= 20 N.s/m, and K1 =K2 = K3 =10 N/m. Plot both x1 and x2 on the same axes.

PROCEDURE:

• Use Step block to provide the input fa(t).• In the Step block, set the initial and final values and the time at which the step occurs.• Select the duration of the simulation to be 10 seconds from the Simulation > Parameters

entry on the toolbar• Write an m-file setting the system parameters,• Include system execution commands in the m-file• Also include plotting statements in the same m-file.• Run the simulation in MATLAB command window and show your work.

EXERCISE 2:

From exercise 1, change the values of B1 = B2= 30 N.s/m and K1 = 20 N/m. Rerun the simulation and compare the responses.

PROCEDURE:

• Make modifications in your m-file to change the parameters given above.• Run your simulation again• Compare the results of Exercise I and 2 and comment on its physical interpretation.

REPORT:

Your report must include:

• Copy of your programs• Results of the programs• Comments on the results• Comparison of results with analytical values where possible

SE 207 Lab # 12Simulation of a Second Order System

IntroductionMany practical system are well approximated by second order models. A general second order model; is given by

where is the damping ratio and is the natural frequency. The damping ratio determines whether the system has oscillatory response or not. A system is called under damped if its response is oscillatory. It is called over damped if has no oscillations. The natural frequency determines the frequency of the oscillations. In this experiment we will study the effect of different parameters on the response of the system.

Part 1:Select a unit step input and let =0.5. Simulate the system for the following values of the damping factor {0, .2, .5, 1 , 2 10}. Plot the response and mark the curves.

What do you observe?

What are the values of the damping ratio that give under damped response?

What are the values of the damping ratio that give damped response?

.

Part 2:Let the input be a unit step and the damping ratio = 0.5. Simulate and plot the response of the system for the following natural frequencies {0.5, 1 , 2 , 10}.

What do you observe?

Part 3: Simulate the system having = 0, =0.5 for the following inputs,

Plot the responses and comment on them.

SE 207-Lab # 13Simulation of Rolling Mill Control

Introduction:

Rolling mills are common in steel industry. Hot slabs are rolled into successively thinner slabs until sheets are formed. This is accomplished by squeezing the material between pairs of rollers. Variations in the thickness of the finished product can be attributed to many factors> These include variations in the material and the hydraulic process that pushes the rollers. A feedback control system is used to control the thickness of the finished product by controlling the hydraulic pressure that push the rollers. A simplified sketch of the rolling process with the control system is shown in figure 1. A block diagram of the system is shown in figure 2. The process and controller parameters are

,

Figure 1: Simplified Sketch of Rolling Control System

Figure 1: Block diagram of Rolling Control System

Transfer functions:

_

GKc Km b/a y

eyr

The transfer function of a linear time-invariant system is defined as the ratio of Laplace transform of the output to the Laplace transform of the input. It is widely used to model of linear systems. SIMULINK offers a simple way of representing transfer functions.

Procedure:Case 1: Simulate the system with the given controller assuming no disturbanceplot the response y(t) and the error signal e(t) when yr is a step of size 0.1 m

Case 2: Assume a sinusoidal disturbance of magnitude 0.02 is applied, Simulate the system with yr being a step of size 0.1 meter and plot the output and the error.

Case 3: Plot the response with uniform random numbers in the range -0.02 and 0.02.plot y(t)

Case 4: Repeat Case 3 with M=900 and plot(y)

SE207: Modeling and SimulationLab # 13

Simulation of the Response of a Car to Road Depressions.

Objective: To simulate a simplified model of a car and investigates the effect of changes in the mass and spring constants as well as the shape of the road depression.

Introduction:

Models of the car suspension systems are important in the design of a car that satisfy the customer’s expectation of a nice ride. Practical car models are used to determine the forces on the deriver and his motion as the car moves on road’s surface.

Cars (at least small cars) have four wheels and each one moves independently as the car moves. Both translational and rotational motion is present. A typical simplified lumped model involves seven degrees of freedom. Translational motion of the four wheels and rotational motion in three axes. In this lab experiment we use further simplification and consider the motion of the front right side of the car and ignore other sides and ignore rotational motion as well.

Figure 1: Simplified model of the car (The right front wheel)

Mb

Mw

Kt

KpBp

y2

y1

u(t)

Procedure:STEP 1: Verify that the mathematical model of the car is given by

where

Typical output of interest are the displacements, velocities and accelerations of the masses.

The model parameters:

STEP 2: Draw simulation diagram

STEP 3: Do the following cases.Case 1: Simulate the system with the parameters above to predict the vertical velocity and accelerations of the driver seat as car moves over a step.u(t) = is a step of magnitude 0.05 meters. Select a suitable time horizon.

Case 2: Simulate the system with the parameters above to predict the vertical velocity and accelerations of the driver seat when the road surface is modeled by

.

Case 3: How does the behavior change when more passengers are added ? Repeat Case 2 with Mb = 350kg and 400 kg.

Case 4: What happen if the tire’s spring constant is reduced to 160 000N/m? Repeat Case 2 with the new spring constant.

Case 5: What happen if the shock absorber damping coefficient is reduced to 90% , and 80% of its original value? Repeat Case 2 with the new damping coefficient.

What to submit?: Derivation of the model ( includes freebody diagrams and equations) Simulation diagrams plot of the input and outputs in the five cases. Comments on the results.