0% found this document useful (0 votes)
12 views17 pages

Lab Session 10 (Simulink)

Uploaded by

no time
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views17 pages

Lab Session 10 (Simulink)

Uploaded by

no time
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

University of Engineering and Technology Lahore

Department of Mechatronics and Control Engineering

LAB 9: Introduction to MATLAB/Simulink


OBJECTIVES:
• To become familiar with the basics of MATLAB/Simulink Model
• To solve transfer functions in Simulink
• To solve state space models in Simulink
• To solve first-order ODE with zero initial conditions
• To solve first-order ODE with non-zero initial conditions
• To solve second-order ODE with zero initial conditions
• To solve second-order ODE with non-zero initial conditions
• To solve the non-linear dynamic model of a simple pendulum system.

INTRODUCTION:
This lab introduces powerful graphical user interface (GUI), Simulink of MATLAB. This software is used for
solving the modeling equations and obtaining the response of a system to different inputs. 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
modeling equations and the digital computer, block diagrams drawn from the system’s differential equations
are used.

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 blocks,
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 parameters. Only a small
subset of the functions of MATLAB will be considered during this lab.

• SUM:

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

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

• GAIN:

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.

• INTEGRATOR:

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 (left). Alternatively, a second input to the block can be displayed to supply the initial condition
explicitly, as in Figure (right). Initial conditions may be specific numerical values, literal variables, or
algebraic expressions.

• CONSTANTS:

Constants are created by the Constant block, which closely resembles Figure. 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.

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

• STEP:

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.

• SIGNAL GENERATOR:

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 (saw tooth), 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.

• SCOPE:

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.

• CLOCK:

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

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

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.

To Workspace:

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 To Workspace
block. In our exercises, all of the state variables and the input variables are usually returned to the workspace.

SOLVING TRANSFER FUNCTIONS IN SIMULINK:


You can simulate any transfer function in Simulink MATLAB with different types of inputs.

Example 1: Check the step response of the transfer function for the RC-series circuit, where R = 1kΩ, C =
1µF.b

𝑉𝑐(𝑠) 1
=
𝑉(𝑠) 𝑅𝐶𝑠 + 1

First of all, you have to save the values of the constant in the workspace of MATLAB; Afterward, drag the
transfer function block, step block, and scope block as shown in the figure.

You can adjust the simulation time to analyze the response of the system.

Quick Hands-on Practice: Simulate the step response of the given transfer function.

7
𝐺(𝑠) =
𝑠2 + 2𝑠 + 7
SOLVING STATE SPACE MODELS IN SIMULINK:
MCT 331 : Modeling & Simulation
Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

In lab 5, we did vehicle suspension system example, whose differential equations are

𝑚2 𝑦2̈ − 𝑘2 (𝑦1 − 𝑦2 ) − 𝑏(𝑦1̇ − 𝑦2̇ ) = 0

𝑚1 𝑦1̈ + 𝑘2 (𝑦1 − 𝑦2 ) + 𝑏(𝑦1̇ − 𝑦2̇ ) + 𝑘1 𝑦1 = 𝑘1 𝑢

Use following parameters for simulation m1=25; m2=1; b=10; k1=30; k2=50;

Simulate system for 10sec and compare the out response for following forcing functions of different
frequencies;b

u=5*sin(2*pi*t);

TASK:
Differential equation of simple mass-spring-damper system is given

𝑀𝑥̈ + 𝐵𝑥̇ + 𝑘𝑥 = 𝐹𝑎 (𝑡)

M=750, B=30, 𝐹𝑎 =300, K=15.


MCT 331 : Modeling & Simulation
Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

Find the step response of this system in Simulink model.

Answer:

Its transfer function is:

1
𝑡𝑓 =
𝑀𝑠 2 + 𝐵𝑠 + 𝐾
Its step function values are:

Its transfer function values are:

Simulink Model:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

Step Input:

Output of step response:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

SOLVING FIRST ORDER DIFFERENTIAL EQUATION:


Example: Solve this expression in MATLAB/Simulink with zero initial conditions.

𝑦̇ (𝑡) + 3𝑦(𝑡) = 𝑒 −𝑡

TASK:
Solve this expression in MATLAB/Simulink with non-zero initial conditions y(0)=1.

𝑦̇ (𝑡) + 3𝑦(𝑡) = 𝑒 −𝑡
MCT 331 : Modeling & Simulation
Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

HINT: Double click on integrator block and change the initial conditions.

Answer:

Simulink Model:

Initial condition:

Output of differential equation:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

SOLVING SECOND ORDER DIFFERENTIAL EQUATION:

Example:Solve this expression in MATLAB/Simulink with zero initial conditions.

𝑦̈ (𝑡) + 5𝑦̇ (𝑡) + 4𝑦(𝑡) = 5cos⁡(2𝑡)

Task:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

Solve the expressions in Matlab/Simulink with zero initial conditions.

Answer:

Initial conditions for dy/dx and y at x=0:

Simulink Model:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

Output of differential Equation:

Solve a third-order differential equation. Use the equation given below and solve it on Simulink.

Answer:

Initial Conditions for d2y/dx2 and dy/dx at x=0:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

Simulink Model:

Output of differential Function:

Solve this expression in MATLAB/Simulink with non-zero initial conditions y(0)=1 &𝑦̇ (0)=0.5

𝑦̈ (𝑡) + 5𝑦̇ (𝑡) + 4𝑦(𝑡) = 5cos⁡(2𝑡)

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

Answer:

Initial Conditions for dy/dt and y at t=0:

Simulink Model:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

Output of differential function system with non-zero initial conditions:

SOLVING NON-LINEAR DYNAMIC MODEL OF SIMPLE PENDULUM IN SIMULINK:

Simulate the non-linear dynamic model of Simple Pendulum with parameters given below:

𝐉𝛉̈ + 𝐁𝛉̇ + 𝐦𝐠𝐥𝐬𝐢𝐧(𝛉) = 𝟎⁡⁡⁡⁡⁡⁡⁡⁡⁡⁡⁡⁡⁡⁡𝐰𝐡𝐞𝐫𝐞⁡𝐉 = 𝐦𝐥𝟐

Mass of pendulum = m = 1 Kg;

Length of pendulum from pivot point to center of mass = l = 1 m;

Damping coefficient of Pivot Point = B = 0.2 N-m/rad/sec;

Gravitational Acceleration = g = 9.81 m/sec^2;

Initial conditions: theta = pi/2 rad, thetadot = 0 rad/sec;

Answer:

Initial Conditions for first and second integrator:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

Simulink Model:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore
University of Engineering and Technology Lahore
Department of Mechatronics and Control Engineering

Output:

MCT 331 : Modeling & Simulation


Department of Mechatronics and Control Engineering, U.E.T. Lahore

You might also like