CH5530-Simulation Lab: MATLAB Additional Graded Session 01/04/2020
CH5530-Simulation Lab: MATLAB Additional Graded Session 01/04/2020
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 .
(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.
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)?