You are on page 1of 5

CourseName: Modeling And Simulation Lab Course code: CSB-443

Experiment:5
Aim:
Write a program to implement the simulation of LAG model.

Task to be done :
LAG simulation is a technique used to study how a model responds to randomly generated
inputs.
There are three types of LAG commands:

1.TT2 = lag(TT1) shifts the data in each variable in TT1 forward in time by one time
step. A shift forward in time is a lag. The row times of TT1 must be regular. The
timetables TT1 and TT2 have the same row times. When you shift the data in each
variable forward, lag fills the first row of TT2 with missing data indicators.
2.TT2 = lag(TT1,n) shifts data by n time steps. n must be an integer. If n is positive, then
lag shifts the data forward in time (a lag). If n is negative, then lag shifts the data
backward in time (a lead).

Name: Rizwan Sadique UID: 19BET1014


CourseName: Modeling And Simulation Lab Course code: CSB-443

3.TT2 = lag(TT1,dt) shifts data by dt, a time interval. dt is either a duration or a calendar
duration. dt must be a multiple of the regular time step of TT1.

Software/apparatus required: - MATLAB R2013A, Personal computer.

Pseudo code/Algorithms/Flowchart/Steps:

1. Create a variable Time which creates a matrix of 5 x 1 of date and time with date in
increasing order.
2. Create a variable name Temp and add another column of Temperatures
corresponding to the Time variable.
3. Create a variable TT1 which completes the table with the values of Time and Temp.
4. Print the table created with values of Time and Temp before adding lag.
5. Create a variable TT2 which adds lag to the values of Temp by 1.
6. Print the table created with values of Time and Temp after adding lag
Code:

Time = datetime('2015-12-18 12:00:00') + days(1:5)';


Temp = [43 42.6 42.3 39.1 37.3]';
TT = timetable(Time , Temp);
TT
TT2 = lag(TT); TT2

Implementation/Output:

Before LAG command:

Name: Rizwan Sadique UID: 19BET1014


CourseName: Modeling And Simulation Lab Course code: CSB-443

Name: Rizwan Sadique UID: 19BET1014


CourseName: Modeling And Simulation Lab Course code: CSB-443

After LAG command:

Name: Rizwan Sadique UID: 19BET1014


CourseName: Modeling and Simulation Lab Course code: CSP-443

Name: Aman Kumar UID: 19BCS1667

You might also like