0% found this document useful (0 votes)
62 views3 pages

CH5530-Simulation Lab: MATLAB Additional Graded Session 01/04/2020

1. The document provides 10 MATLAB programming exercises involving vectors, loops, functions, plotting, solving differential equations, and an epidemiological model. 2. Exercise 10 asks the reader to write code to model the spread of a disease using the SIR model with susceptible, infected, and recovered populations. The reader is asked to derive equations for the rates of change and see how the infected curve changes with reproduction number R0. 3. The reader is also asked to vary the rate of spread k1 while holding the recovery rate k2 constant, and observe how the infected curves change shape. Flattening occurs at lower k1 values, corresponding to better social distancing. Perfect social distancing results in no disease spread.
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)
62 views3 pages

CH5530-Simulation Lab: MATLAB Additional Graded Session 01/04/2020

1. The document provides 10 MATLAB programming exercises involving vectors, loops, functions, plotting, solving differential equations, and an epidemiological model. 2. Exercise 10 asks the reader to write code to model the spread of a disease using the SIR model with susceptible, infected, and recovered populations. The reader is asked to derive equations for the rates of change and see how the infected curve changes with reproduction number R0. 3. The reader is also asked to vary the rate of spread k1 while holding the recovery rate k2 constant, and observe how the infected curves change shape. Flattening occurs at lower k1 values, corresponding to better social distancing. Perfect social distancing results in no disease spread.
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/ 3

CH5530-Simulation Lab

MATLAB Additional Graded session

01/04/2020

 
1. A vector is given by x = −3.5 −5 6.2 11 0 8.1 −9 0 3 −1 . U sing conditional statement
and loops, write a program that creates two vectors from x, one p, which contains all the positive entries
and other n containing the negative entries.

2. It has been suggested that the population of the United States may be modeled by the formula:
197273000
P(t) =
1 + e(−0.03134(t−1913.25))
where ’t’ is the date in years. Write a program to compute and display the population every ten years
from the year 1790 to 2000. Plot a graph of the population against time as well. Find out whether (and if
it does find out when) the population reaches a steady state.

3. Write MATLAB programs to find the following sums using for loop and without using for loop (vector-
ization).

(a) 12 + 22 + 32 + . . . + 10002
(b) 1 − 31 + 51 − 17 + 91 − . . . − 1003
1

1
(c) 12 32
+ 32152 + 52172 (with 500 terms)

4. Write a generic code to get an input n from the user and print the fibonacci numbers up to the nth term.

• Using loops
• Using recursion

5. A projectile is fired at an initial velocity of 50 m/s at an angle of 5012π radians (with the horizontal axis).
The initial vertical and horizontal position of the projectile are given by x0 = 0 and y0 = 0. Find the
maximum distance (horizontal) the projectile will travel. Plot the x vs. t and y vs. t in separate graph for
t = 0 to t = 10. Assume no air friction and g = 9.81 m/s2 .

6. Given a quadratic function,


y = 2x2 + 5x + 3
Plot and show where the function value goes to zero. Write a function named ’func_solution’ to calcu-
late the roots of the quadratic function. Obtain the discriminant in the quadratic formula using another
function file named ’func_discriminant’ and call it inside the ’func_solution’ function file to obtain the
roots.

7. Write a function which takes a 4 digit number as input and returns :

(a) Largest possible number that can be formed from the digits of the number which was given as input.
(b) Smallest possible number that can be formed from the digits of the number which was given as
input.
(c) The difference of the numbers that you obtained in options (a) and (b).

1
for example:
Case 1: Input: A = 2867
Output : Largest = 8762; Smallest = 2678; Difference = 6084;
Case 2: Input = 261;
Output = Given number is not a 4 digit number.

8. Consider the ODE:


dy x
=
dx (x2 + 8)

Using Euler’s explicit method find out the function values at x ∈ [1, 2] for step size of 0.1 (DO NOT USE
ODE solver, USE loops)

9. For the system, A x = b where A is any n × n full rank matrix and b any n × 1 vector, write a generic code
to perform basic row operations(Gauss elimination) without using in–built MATLAB command.
1 2 5 8
 
0 3 2 1  T
for example: A =   and b = 3 2 1 4
 
5 5 6 3
7 9 11 2
1 2 5 8 3
 
0 3 2 1 2 
Row operations on the augmented matrix result in 
 

0 0 9.4 21.2 6.4 
0 0 0 2.6032 −0.1839
10. Lockdown? Who?
All you see around you, in newspaper articles, TV channels, online streaming services these days is the
talk of the CoVID-19 outbreak and its implications and so, we did not want to be the ones to disappoint
you in this regard.
Let us try to understand what the epidemic gurus are speaking about when they talk of R0(reproduction
number of the disease) and social distancing in the context of an epidemic spread. This can be done by
looking at a simplistic epidemic model, the SIR model. Consider a population of size N, which is divided
into three sections in this scenario,
St is the number of healthy individuals that are susceptible to getting infected, at time t
It is the number of infected individuals at any time t
Rt is the number of individuals that have recovered from the disease at time t
(Hint: population remains the same throughout)
k
St + It −−1→ It
k
It −−2→ Rt
Write down the expressions for the rate of change of St , It and Rt . What do the numbers settle to, starting
with one infected person? (for N = 500, k1 = 6 , k2 = 5 which are the rate constants for the infection
spread and recovery respectively).
(Hint: rate of change of St (in a day) = (St+1 − St ) = −k1 St NIt , where It
N is the probability of a susceptible
person coming in contact with an infected person)

2
At small t, when SNt ∼ 1, It ∼ I0 e[−k2 (R0 −1)] and it can be seen that for R0 < 1, the number of infected
person graph dies out. Write R0 in terms of k1 and k2 .
k1 or the rate of spread van be controlled by social distancing (effective lockdown)
k2 is dependent on the region’s healthcare infrastructure
Change k1 for a fixed k2 in the original simulation for 4 values of R0 falling between 0 and 4. How does
the shape of the infected curve change with varying k1 values? At what relative values of k1 does the
curve tend to flatten. Plot the curves to support your answer and use legend for distinguishing among
the curves with different k1 values. What happens when perfect social distancing is achieved (plot your
result)?

You might also like