关键词 > MATH6005/6181

MATH6005/6181 Assignment 2

发布时间:2023-03-10

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

MATH6005/6181 Assignment 2

MATH6005: Worth 40%

MATH6181: Worth 20%

Submission date: Friday 10th March 17:00

 

Rules for Assignment 2

You MUST upload one single file on Blackboard.

The file name, with all functions inside, must be of the form  <university username>.py.   For example: mpka1e21.py.

 ALL functions MUST follow the prototypes provided.

 You will have access to two data files.

 You MUST submit by the deadline and you MUST submit your own work. You are welcome to work with others but DO NOT copy directly from another students code.  Any late submission will be docked marks according to the late submissions policy.

 Your code MUST run without any errors, if there are errors these will be penalised.

Your code must be commented throughout to obtain a high mark.

TASK 1

[20 points] The Gaussian distribution is given by the following probability density function

f(x) =  (  )2 ,                                                               (1)

where σ is the standard deviation and µ is the mean of the distribution.  Your task is to first implement a function which that takes as an input a real number x and returns f(x) according to equation 1.  You will

then plot f(x) for the following values of µ and σ 2  for 4 4:

µ = 0  σ 2  = 0.2

µ = 0  σ 2  = 0.4

µ = 0  σ 2  = 4

µ = 2  σ 2  = 0.5.

Function Behaviour

• The function must plot each curve on the same set of axes and show an axes legend where each curve is labelled with a different colour/ plot style.

• There must be x and y axes labels added.

TASK 2

[20 points] The Collatz sequence is generated by applying the following rules to an integer value and then to each resulting integer in turn, until the number 1 is reached.

• If the integer is even, divide by 2.

• If the integer is odd, multiply by 3 and add 1.

Examples

n = 8  =n = 8/2 = 4  =n = 4/2 = 2  =n = 2/2 = 1.

n = 5  =n = 3 * 5 + 1 = 16  =n = 16/2 = 8  =n = 8/2 = 4  =n = 4/2 = 2  =n = 2/2 = 1

Your task is to implement a function that given two positive integers n and m, returns a string explaining which integer reaches the number 1 in the fewest iterations. For example, for n = 4 and m = 8 the function should return n=4 took 1 fewer iterations than m=8 to reach 1.

Function Behaviour

• The function should return the sentence outlined in the previous paragraph. The function should also take into account if n and m are swapped around and return the same statement.  i.e.  for the case above m=4 took 1 fewer iterations than n=8 to reach 1 should be returned.

• The function should be well documented, explaining the inputs and the outputs.

• The function should follow the prototype provided.

TASK 3

[30 points] You are given a data sheet in a CSV file of the number of sunshine hours per city for each month of the year and the total yearly sunshine hours for each city. Your task is to:

• Find the continent with the yearly largest average sunshine hours, then return the name of the conti- nent.

• Find the city with the smallest number of sunshine hours in the month of July and return the name of the city.

• Find the 12 cities with the lowest sunshine hours in the month of January. Then produce a bar chart of these cities of their yearly sunshine hours. Return the histogram from the function.

• You MUST use the pandas package.

TASK 4

[30 points] You need to calculate the area of an irregular polygon.  The polygon is defined by a counter- clockwise sequence of points (coordinates) Pi  = (xi ,yi ), i ∈ (1,n). The area can be calculated via

n − 1

i=1

You are given a CSV file with the coordinates.

• Using the prototype provided, write a function that calculates and returns the area A.

• Using the prototype provided, write a function that minimises the area by removing one point.  The function must return the point that minimises the area and the value of the minimal area.