Sie sind auf Seite 1von 2

Assignment 2

MATLAB classes IITGN

August 13, 2018

Deadline : 18/5/2018 5:30 pm

Question 1 : Predator-Prey Model


Consider two populations whose sizes at a reference time t are denoted by x(t) (prey)
, y(t) (predator), respectively. The functions x and y denotes scaled measure of the
population sizes, but are taken to be continuous functions. Changes in population size
with time are described by the time derivatives ẋ = dx/dt and ẏ = dy/dt , respectively,
and a general model of interacting populations is written in terms of two autonomous
differential equations
ẋ = (b − py)x , ẏ = (rx − d)y (1)
Solve this system of equations using Euler’s method as taught in class. Plot how population
of prey and predator vary with time on the same plot.

Question 2 : Counting Primes


Input a large number (∼ 10000) from user. Write a MATLAB program to count how
many primes are less than or equal to that number. Also, export all the prime numbers
to an excel file in following manner.

index i ith prime (ni )


1 2
2 3
3 5
4 7
. .
. .
. .

Also, plot i vs ni in excel. Show proper labels to axes.

1
Question 3 : Alternating Harmonic Series
Harmonic series is given by following equation.
n
1 1 1 1 X (−1)i
Sn = − + − · · · + (−1)n = (2)
1 2 3 n i
i=1

Write a MATLAB function to calculate Sn for given value n. Plot Sn as a function of n


till a very large number n and see if it approaches the value ln 2. Show the dotted line
(y = ln 2) in the same plot for comparison.

Question 4 : Matrix Multiplication


Write a MATLAB program to multiply two n × n matrices. Take n as input from user and
input both matrices. You have to use for loop for the same. DO NOT use the MATLAB
in-built ’*’ to multiply the matrices.

Question 5 : Matrix Multiplication


Create a MATLAB structure data type to input Name and Birth date of a student. Birth
date should be structure containing date, month and year. Input details of 20 students in
the structure. Also, write a program to count how many students are born in each month.

Das könnte Ihnen auch gefallen