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

EMAT10007 – Introduction to Computer Programming

Assignment 2022 – Building Programs

Overview

In this assignment, you will complete two short computational modeling exercises.  The exercises will require you to take a real-life problem and translate it into a computer model in order to output a solution.

What you need to submit

Your answer to each of the two questions should be submitted as a separate zipped (.zip) folder (named‘part1.zip’,‘part2.zip’). Each folder must contain:

1. The Python (.py) file(s) needed to run your program as well as any other files needed to run the program (e.g. plain text data files)

2. A README.txt plain text file that explains how your program should be run. The assessor will use these instructions to run your program.   Programs that do  not run will be awarded marks of zero.

Example README.txt contents:

Run  python  file main .py

3. A report.pdf file (page limit: 2 pages; minimum font size: 11) explaining where and how the following dimensions were used in the program you wrote for each part:

i Data handling: Choice and use of data types.

ii Selection: Controlling the flow of a program.

iii Repetition: Executing a process multiple times.

iv Modularity: Packaging code into reusable blocks.

This could, for example, be formatted as a table like the one below:

 

Data Handling

Selection

Repetition

Modularity

Part 1

e.g.  <Data  type> was chosen to...

Selection        was achieved by ...

 

 

Part 2

 

 

 

 

The submission point can be found on Blackboard.

The deadline is 13:00 on Friday 9th December

Mark Scheme

The program must run! The assessor will not edit broken code to make it work. If the program does not run, then marks of zero will be awarded.

For each of the two questions you will achieve up to a total of 100% – the mark scheme is broken down in the table below.

For each program (parts 1 and 2):

• You will be given a mark out of 100 for your use of data handling, selection, repetition and modularity in your program and the documentation of this in your report.  Each has a weighting of 15%.

• You will be given a mark out of 100 representing the percentage of the correct solutions your model outputs (maximum of 3 correct solutions for each part). This has a weighting of 30%.

• You will be given a mark out of 100 representing the percentage of the best practises shown in the table, that you used in your program. This has a weighting of 10%.

Therefore your final mark for each part (1 and 2) will be calculated as follows:

Total mark for each part = (marks for data handling × 15%) + (marks for selection × 15%) + (marks for repetition × 15%) + (marks for modularity × 15%) + (marks for correct solution × 30%) + (marks for best practise × 10%)

Your mark will be the average of your scores for parts 1 and 2.

The mark that appears on blackboard will be the average of your scores for Coursework 1 and Coursework 2.

Helpful hints and suggestions

Incremental development is a way of programming that can make debugging your program easier. The steps are:

1. Always start with a working program, however short.  Start with something you know is correct, like x=5 and run the program and confirm that it does what you expect.

2. Make one small, testable change at a time. A testable change is one that displays something or has some other output you can check.

3. Run the program and see if the change worked. If so, go back to Step 2. If not, you will have to do some debugging, but it shouldn’t take long to find the problem as the change you made was small.

Part 1 - Climate modelling - Predicting sea level rise

Climate models are important tools that incorporate climate data and theoretical analysis to try to understand and predict climate behaviour. The Maldives (Figure 1a) is located south-southwest of India.  It consists of approximately 1,190 islands and is the lowest country in the world with a maximum elevation of 2.4 m (data recorded in 2010), making it particularly vulnerable to sea level rise. The Solomon Islands (Figure 1b) is a nation of hundreds of islands in the South Pacific, southeast of Papua New Guinea, comprised of a collection of 992 distinct islands. Of these islands, five disappeared due to rising sea levels from 1947 to 2014.

The data contained in files maldives data .csv and solomon data .csv shows the annual aver- age sea level recorded on Hulhule Island  (Maldives), and Guadalcanal  (Solomon Islands) from 1994 to 2022.   The sea level r(t) for a given year, t, is given relative to the sea level in year 2010, so r(2010)  =  0.   The data was compiled by the University of Hawaii Sea Level Center (http://uhslc.soest.hawaii.edu/data/download/fd).

Land masses have irregular shapes that are difficult to model exactly so geometric approximations using regular shapes are often used in climate modelling.  The Maldives and the Solomon Islands can each be represented as a triangular prism (Figure 1c). The width of the base w, length of the base l, and height of the prism e (representing the width, length and elevation of the area of land above sea level in 2010, respectively) are given in Table 1.

The elevation of land above sea level e(t) for a given year, t, can be found by:

e(t) = e(2010) − r(t)

where e(2010) is the elevation of land above sea level in 2010 (Table 1). As sea level rises, the width of the base of the prism, w(t), representing the land above sea level, can be calculated by:

w(2010)

w(t) = e(t) ×

where w(2010) is the width in 2010 (Table 1).  As the length of the prism, l  (Table 1) remains constant with respect to time, the area of the base of the prism a(t), representing the land above sea level can be found by:

a(t) = l × w(t).

1.  Fit two functions for r(t) to the data in each of the two files maldives data .csv and in solomon data .csv:

• A simple linear linear function (of the form r(t) = it + j, where i and j are constants)

• A more complex quadratic function (of the form r(t) = it2 + jt + k, where i, j and k are constants)

Display the root mean square error (RMSE), in units m, of each function fitted to the raw data.

1 mark for outputting the correct solution: value of the root mean square error for each of the four functions

2.  It is computationally more efficient to use a simpler model where possible.  While a more complex model can give greater accuracy, if the increase in accuracy is small, it may not be worth the extra computational demand.

For each country (Solomon Islands, Maldives), use the RMSE of the two fitted functions to decide whether to use the simple linear model or the complex quadratic model for the rest of this question. Use the simple linear model if:

• the RMSE of the linear function is lower than the RMSE of the quadratic function

OR

• the RMSE of the quadratic function is lower than the RMSE of the linear function, but by a difference of less than than 0.1 m.

Otherwise, use the more complex quadratic model.

Then, for each country, using the model you have selected and the triangular prism represen- tation given in Figure 1, plot the predicted land mass area a(t), in units km2  for the years 2030 to 2100.  The graphs for the two countries must have correct axis labels and should each be saved as a separate .pdf file named ‘maldives.pdf’and ‘solomon.pdf’respectively.

1 mark for outputting the correct solution:  coordinates of points plotted for each country

3.  According to your model how many years will it take the area of the Maldives to decrease by 10% of its area in 2030. Give your answer as the closest integer value.

1 mark for outputting the correct solution: number of years

 

Figure 1: (a) Map of the Maldives, (b) Map of the Solomon Islands (vemaps.com). (c) Triangular

prism model with annotations showing sea level r, elevation of land above sea level e, width of land above sea level w, length of land above sea level l, and area of land above sea level (area bounded in red) a.

Table 1: Values of the elevation above sea level in 2010, e(2010), the width in 2010, w(2010), and the length l, used in the triangular prism model of the Maldives and the Solomon Islands.

Country

e(2010) m

w(2010) m

l

m

Maldives

2.4

1,000

298,000

Solomon Islands

2,335

50,000

578,000

Part 2 - Heating of lithium-ion batteries

ePower is a (fictional) company that designs lithium-ion batteries for electric vehicles.  The tem- perature of a lithium-ion battery must not exceed 60 C. If the temperature exceeds 60  C, then the battery will be unsafe because it can overheat and explode.  ePower has developed three new battery designs, but they are not sure which of these are safe to use. Your task is to use program- ming to determine the safe battery design(s).

The temperature of a battery, T(t), can be described by the equation

RI(t)2

T(t) = Tair +    hair     ,                                                                (1)

where t is time, Tair  is the air temperature, R is the resistance of the battery, I(t) is the time- dependent current being drawn from the battery, and hair  describes how fast the battery cools due to heat exchange with the air. The parameter values for each battery design are listed in Table 2. The electric current I(t) is provided in the file current_measurements .csv.

Write a Python program that

1. Computes the temperature of each battery as a function of time using Equation (1).  The maximum temperature of each battery should be printed to the screen along with a message that indicates whether the battery is safe to use or not.

1 mark for outputting the correct solution:  max temperature value and if the battery is safe or not

Table 2: Parameter values for the three battery designs.

Symbol   Description (unit)                         Design 1        Design 2        Design 3

Tair          Air temperature (C)                         23                  23                  23

R        Battery resistance (Ohm)            3.0 × 10 4        5.8 × 10 4        6.1 × 10 4

hair          Heat transfer with air (W/C)    1.86 × 10 4      6.59 × 10 4      2.48 × 10 4

Most electric vehicles are powered by a pack of batteries. Let’s consider a battery pack consisting of three batteries that are connected in parallel, as shown in Figure 2.  Each battery in the pack has its own resistance (Rn), electric current (In), and temperature (Tn), where n = 1, 2, 3.

The current through each battery, In, can be obtained using equivalent circuit formulae as

In(t) = I(t),    Requiv = (  +  + )1 .                                (2)

The temperatures of the three batteries in the pack, T1 , T2, and T3, can be determined by solving the linear system of equations given by

 hair + hbatt

(    0(hbatt)

hbatt 2hbatt hbatt

0        

 

 T(T)2(1)           1(2)

(3)

 

Figure 2: Illustration of a battery pack composed of three batteries connected in parallel.

where hbatt  describes how fast heat is transferred from one battery to another.  ePower engineers have determined that R1  = 3.3 × 10 4  Ohms, R2  = 3.0 × 10 4  Ohms, R3  = 3.2 × 10 4  Ohms, hair  = 1.9 × 10 4  W/C, and hbatt  = 4.8 × 10 5  W/C. Using Tair  = 23 C and the current I(t) provided in current_measurements .csv, write a program that:

2. Outputs a CSV file called pack_temperature .csv that contains the temperature of each battery, the mean temperature of the three batteries, and the maximum temperature of the three batteries, at each point in time. The CSV file must be arranged in the format shown in Table 3. Your program should print a message to the screen that informs the user whether the battery pack is safe to use or not. The battery pack will be unsafe if the temperature of any of the batteries exceeds 60 C.

1 mark for outputting the correct solution:  battery 1, 2, 3 temperature, mean and max temperature. Battery safe / not safe value.

3. Calculates the maximum current I that can be applied to the battery pack before it becomes unsafe to use.  The current should be found within to 0.01 A. Print the current that was found to the screen.

1 mark for outputting the correct solution: maximum current.

Table 3:  Required format of the output file pack temperature .csv.  The mean temperature is defined as the mean of T1 , T2, and T3 . The maximum temperature is defined as the maximum of T1 , T2, and T3 . The horizonal and vertical lines are for illustration purposes and should not appear in the CSV file.

Time (s)   T1      T2      T3      Mean temperature (C)   Maximum temperature (C)

0

1

2

 

1800

...    ...    ...

...    ...    ...

...    ...    ...

...    ...    ...

...    ...    ...

...

...

...

...

...

...

...

...

...

...