1. Homepage
  2. Programming
  3. COMP2421 Numerical Computation - Coursework: Differential Equations

COMP2421 Numerical Computation - Coursework: Differential Equations

Engage in a Conversation
LeedsCOMP2421XJCO2421Numerical computationPythonDifferential Equations

School of Computing: assessment brief CourseNana.COM

Module title CourseNana.COM

Numerical computation CourseNana.COM

Module code CourseNana.COM

COMP/XJCO2421 CourseNana.COM

Assignment title CourseNana.COM

Final coursework CourseNana.COM

Assignment type and description CourseNana.COM

Coursework. Exploring methods for solving differential equations. CourseNana.COM

Rationale CourseNana.COM

Testing the understanding of learning outcomes in practical situation CourseNana.COM

Word limit and guidance CourseNana.COM

Suggested word limit given in each section totalling 650 words CourseNana.COM

Weighting CourseNana.COM

Submission dead- line CourseNana.COM

2pm Wed 20 Dec CourseNana.COM

Submission method CourseNana.COM

Gradescope CourseNana.COM

Feedback provision CourseNana.COM

Written group feedback CourseNana.COM

Learning outcomes assessed CourseNana.COM

- Use, data-based arguments to justfy choosing a compu- tational algorithm appropriately, accounting for issues of accuracy, reliability and efficiency;
- Understand how to assess/measure the error in a nu- merical algorithm and be familiar with how such errors are controlled;

- Implement simple numerical algorithms accurately and present results in a variety of forms. CourseNana.COM

Module lead CourseNana.COM

Thomas Ranner CourseNana.COM

Other Staff contact CourseNana.COM

(COMP) Yongxing Wang, (XJCO) Zhiguo Long CourseNana.COM

1. Assignment guidance
In this coursework, you will use software libraries to explore different numerical schemes CourseNana.COM

and you will analyse the methods and results. CourseNana.COM

2. Assessment tasks CourseNana.COM

In this coursework, you will be writing a report for your boss as BigNumComp Inc helping them to choose a numerical method. You should assume she has the knowledge of second year undergraduate Computer Science student at the University of Leeds. CourseNana.COM

Problem CourseNana.COM

Your boss wants to find good numerical methods for solving predator-prey models. Predator-prey models describe the evolution of two different co-existing species: one is the predator and one is the prey. CourseNana.COM

The problem can be described through the following system of differential equations for x(t), the prey, and y(t) the predator: CourseNana.COM

dx = αx βxy + f(t) dt CourseNana.COM

dy =δxyγy+g(t), dt CourseNana.COM

where α, β, γ, δ are positive real numbers and f and g are given functions of t which relate to external migration into or out of the system. CourseNana.COM

Your boss, helpfully, suggests two test cases for you to consider: CourseNana.COM

  1. (a)  Usetheparametersetα=β=γ=δ=1, CourseNana.COM

    f(t)=sin(t)(cos(t))2 cos(t) g(t)=sin(t)+(cos(t))2 cos(t), and initial condition x(t = 0) = 2 and y(t = 0) = 0, which has exact solution CourseNana.COM

    x(t) = 1 + cos(t) y(t) = 1 cos(t). CourseNana.COM

  2. (b)  Use the parameter set α = 2/3= 4/3= 1= 1, f(t) = 0, g(t) = 0 and x(t = 0) = 0.9,y(t = 0) = 0.9. For this case there is no nice form for the exact solution but your boss tells you that the solution should repeat itself and the maxima of each population should be consistent (i.e. not change) over time. CourseNana.COM

You are tasking with finding the best solver in terms of accuracy and efficiency. You should write a report (following the template laid out below) evidencing your recom- mendations and reasoning. CourseNana.COM

Task CourseNana.COM

You recognise this problem as being solvable as a system of differential equations. You have seen some methods in the course but know there are better methods available. In CourseNana.COM

2 CourseNana.COM

your preliminary research you find a company internal solver for systems of differential equations (attached as solvers.py). You will solve and analyse the results of solving the predator prey model for two different methods within solvers.py and one method from the module which you think is the most appropriate for this problem. CourseNana.COM

You should include all the sections in the template in your report. There is guidance of what to include in each section and a guidance word limit for each section too. Code, tables and equations do not count in the word limit. The word limit is only guidance and no penalties will be introduced for going over the limit. You should aim to write less than the word count to ensure your writing is concise and understandable to your audience. CourseNana.COM

You should submit a jupyter notebook including all computations as your report. You should write in full sentences throughout to guide the reader through what you are doing. There is no need to include the file solvers.py in your solution. You should write text in Markdown blocks and include all code for the implementation and generating results in Code blocks. CourseNana.COM

Library documentation CourseNana.COM

solvers Solve differential equations.
Solve the differential equation(s) specified by

y(t) = f(t, y) subject to y(t0) = y0.
The problem is solved using a specified method from t0 to a final time T using a time CourseNana.COM

step dt. Parameters CourseNana.COM

rhs A python function describing the right hand side function f of the differential equation. The function takes two arguments: the first represents t for time and the second represents the solution y which may be either a floating point type or a numpy array for the case of multiple differential equations. CourseNana.COM

y0 The starting value of y - accepts either a floating point type or a numpy array for the case of multiple differential equations. CourseNana.COM

t0 The starting time t0. CourseNana.COM

dt The time step dt. CourseNana.COM

T The final or stopping time. CourseNana.COM

method The method used to advance the solver given as a string. The method should be one of CourseNana.COM

"Van De Houwen" CourseNana.COM

"Runga-Kutta" "3/8-rule"
"Ralston-4". CourseNana.COM

Returns CourseNana.COM

t The time points where the solution was found as a list y The estimate of the solution at each time point as a list CourseNana.COM

Sample code CourseNana.COM

Download the file solver.py and place it in the same folder as your code. An example for solving the a single differential equation: CourseNana.COM

from solvers import solver def rhs(t, y): CourseNana.COM

return -y CourseNana.COM

y0 = 1.0 t0 = 0.0 dt = 0.1 T = 1.0 CourseNana.COM

t, y = solver(rhs, y0, t0, dt, T) CourseNana.COM

An example for solving the a system of differential equation: CourseNana.COM

import numpy as np CourseNana.COM

from solvers import solver CourseNana.COM

def rhs(t, y):
return np.array([-y[1], y[0]]) CourseNana.COM

y0 = np.array([1.0, 0.0]) t0 = 0.0
dt = 0.1
T = 1.0

t, y = solver(rhs, y0, t0, dt, T) CourseNana.COM

Solution template CourseNana.COM

  1. (a)  Implementation. Write code to be able to run three methods you have chosen for arbitrary initial conditions (x(t = 0), y(t = 0)), time step (dt), model parameters (α, β, γ, δ) and functions f and g. [50 words] CourseNana.COM

  2. (b)  Results. Simulate and show results for each of the test cases suggested by your boss for a range of time steps until a final time T . For test case 2a, you should use T = 2.5π and (at least) dt = T/100,T/200,T/400,T/800,T/1600. For test case 2b, you should use T = 30 and (at least) dt = T /100, T /200, T /400, T /800, T /1600. You should demonstrate how solutions look for each method, and the accuracy and efficiency of each approach. [50 words] CourseNana.COM

  3. (c)  Analysis. Comment on the efficiency and accuracy of each approach. [250 words] CourseNana.COM

  4. (d)  Conclusion. Compare the methods that you have results for, and any other rel- evant methods from the module, and make a recommendation of which method you think is best. [300 words] CourseNana.COM

3. General guidance and study support
Examples of how to approach each aspect of this coursework is given in lectures and CourseNana.COM

using the online notes. CourseNana.COM

You may wish to read more about predator prey models (also known as Lotka Volterra equations) to help with your analysis: CourseNana.COM

Wikipedia: Lotka Volterra equations Mathworld: Lotka Volterra equations CourseNana.COM

Further support for this assessment is given through the MS Class Team. Details of further support sessions will be given closer to the deadline. CourseNana.COM

4. Assessment criteria and marking process CourseNana.COM

Your work will be assessed on your code implementation, your results and their pre- sentation, your analysis of the method and results, and your writing quality. Work will be marked as a final assessment for this module so your mark will only be given back as part of your final grade. CourseNana.COM

5. Presentation and referencing
The quality of written English will be assessed in this work - further details in the CourseNana.COM

Rubric below. As a minimum, you must ensure: CourseNana.COM

  • Word choice and grammar do not seriously undermine the meaning and compre- hensibility of the argument CourseNana.COM

  • Word choice and grammar are generally appropriate to an academic text
    These are pass/ fail criteria. So irrespective of marks awarded elsewhere, if you do not

    meet these criteria you will fail overall. CourseNana.COM

    6. Submission requirements CourseNana.COM

    Please submit your work via Gradescope by the deadline given. You should submit a jupyter notebook with all your code, text and results included in a single document. You are recommended to “reset the kernel” and “Run all cells” again before you submit. CourseNana.COM

  1. Academic misconduct and plagiarism CourseNana.COM

    • Leeds students are part of an academic community that shares ideas and develops CourseNana.COM

      new ones. CourseNana.COM

    • You need to learn how to work with others, how to interpret and present other people’s ideas, and how to produce your own independent academic work. It is essential that you can distinguish between other people’s work and your own, and correctly acknowledge other people’s work. CourseNana.COM

    • All students new to the University are expected to complete an online Academic Integrity tutorial and test, and all Leeds students should ensure that they are aware of the principles of Academic integrity. CourseNana.COM

    • When you submit work for assessment it is expected that it will meet the Univer- sity’s academic integrity standards. CourseNana.COM

    • If you do not understand what these standards are, or how they apply to your work, then please ask the module teaching staff for further guidance. CourseNana.COM

      By submitting this assignment you are confirming that the work is a true expression of your own work and ideas and that you have given credit to others where their work has contributed to yours. CourseNana.COM

  2. Assessment/marking criteria grid
    The final assessment will be marked out of 50 according the following rubric. Algorithm implementation (10 marks) CourseNana.COM

    6 CourseNana.COM

Marks Description CourseNana.COM

9-10 Algorithm(s) implemented accurately and efficiently. Professional quality code (Uniform formatting, unit tests CourseNana.COM

where appropriate). No efficiency problems. Informative comments. CourseNana.COM

7-8 Algorithm(s) implemented with no errors. Some efficiency problems. Helpful comments throughout. CourseNana.COM

6-7 Algorithm(s) implemented with no errors. Some helpful comments. CourseNana.COM

5-6 Algorithm(s) implemented with minor errors. Some comments. CourseNana.COM

0-4 Serious issues with code implementation resulting in inaccurate results. CourseNana.COM

Presentation of results (15 marks) CourseNana.COM

Marks Description CourseNana.COM

13-15 Results in a variety of appropriate formats (i.e. tables, plots, etc). Results and extensive additional useful CourseNana.COM

information shown. Plots and tables labelled accurately. CourseNana.COM

10-12 Results in a variety of appropriate formats (i.e. tables, plots, etc). Results and additional useful information CourseNana.COM

shown. Plots and tables labelled accurately. CourseNana.COM

7-9 Results in a variety of appropriate formats (i.e. tables, plots, etc). Results accurately shown. CourseNana.COM

4-6 Attempts are carefully formatting results suitable for technical audience. Results accurately shown. CourseNana.COM

0-3 Basic or very limited results shared. CourseNana.COM

7 CourseNana.COM

Analysis of results (20 marks) CourseNana.COM

Marks Description CourseNana.COM

17-20 Critical explanations using additional computational experiments and making reference to appropriate CourseNana.COM

external literature covering all methods CourseNana.COM

13-16 Critical explanations using additional computational experiments covering all methods CourseNana.COM

9-12 Descriptive explanations using further analysis of suggested computational experiments covering all CourseNana.COM

methods CourseNana.COM

5-8 Descriptive explanations based purely on suggested experiments covering all methods CourseNana.COM

0-4 No or very limited results explained CourseNana.COM

Writing (5 marks) CourseNana.COM

Marks Description CourseNana.COM

5 Outstanding structure and clarity of writing, all in a suitable language. No errors. CourseNana.COM

4 Clear structure and writing in suitable language. Some minor errors. CourseNana.COM

3 Well structured with mostly clear writing in suitable language. Some errors. CourseNana.COM

2 Structure could have been improved. Some text required careful reading. Language not appropriate for technical CourseNana.COM

report. CourseNana.COM

Marks Description CourseNana.COM

1 Poor presentation and structure with unclear or confusion descriptions. Many errors. CourseNana.COM

A External library reference CourseNana.COM

The source code for solvers.py: CourseNana.COM

from typing import Callable , List , Tuple , TypeVar import numpy as np CourseNana.COM

# Butcher tables for each of the methods used CourseNana.COM

TABLEAU = { "Heun": ( CourseNana.COM

np.array([[0.0, 0.0], [1.0, 0.0]]), np.array([0.5, 0.5]), np.array([0.0, 1.0]), CourseNana.COM

), "Ralston": ( CourseNana.COM

np.array([[0.0, np.array([0.25, np.array([0.0, 2 CourseNana.COM

"Van der Houwen": ( CourseNana.COM

np.array([[0.0, 0.75, 0.0]]), CourseNana.COM

np.array([2 / 9, np.array([0.0, 1 CourseNana.COM

), "SSPRK3": ( CourseNana.COM

0.0], [2 / 3, 0.0]]), 0.75]), CourseNana.COM

/ 3]), CourseNana.COM

0.0, 0.0], [1 / 2, 0.0, 0.0], [0.0, CourseNana.COM

1 / 3, 4 / 9]), / 2, 3 / 4]), CourseNana.COM

np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.25, 0.25, 0.0]]), CourseNana.COM

np.array([1 / 6, 1 / 6, 2 / 3]), CourseNana.COM

np.array([0.0, 1.0, 1 / 2]), ), CourseNana.COM

"Runge -Kutta": ( np.array( CourseNana.COM

[0.0, 0.0, 0.0, 0.0],

[0.5, 0.0, 0.0, 0.0], [0.0, 0.5, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], CourseNana.COM

np.array([1 / 6, 1 / 3, 1 / 3, 1 / 6]), CourseNana.COM

np.array([0.0, 0.5, 0.5, 1.0]), ), CourseNana.COM

"3/8-rule": ( np.array( CourseNana.COM

[0.0, 0.0, 0.0, 0.0],
[1 / 3, 0.0, 0.0, 0.0], [-1 / 3, 1.0, 0.0, 0.0], [1.0, -1.0, 1.0, 0.0],

] ), CourseNana.COM

np.array([1 / 8, 3 / 8, 3 / 8, 1 / 8]), CourseNana.COM

np.array([0.0, 1 / 3, 2 / 3, 1]), ), CourseNana.COM

"Ralston -4": ( np.array( CourseNana.COM

[0.0, 0.0, 0.0, 0.0],
[0.4, 0.0, 0.0, 0.0],
[0.29697761, 0.15875964, 0.0, 0.0], [0.21810040, -3.05096516, 3.83286476, 0.0],

] ), CourseNana.COM

np.array([0.17476028, -0.55148066, 1.20553560, 0.17118478]), CourseNana.COM

np.array([0.0, 0.4, 0.45573725, 1.0]), ), CourseNana.COM

} CourseNana.COM

# types for y variable in solver CourseNana.COM

y_type = TypeVar("y_type", np.ndarray , np.double) CourseNana.COM

def solver(
rhs: Callable[[np.double, y_type], y_type], y0: y_type ,

str, CourseNana.COM

) -> Tuple[List[np.double], List[y_type]]: CourseNana.COM

Solve the differential equation(s).

Solve the differential equation specified by CourseNana.COM

y’(t) = rhs(t, y) subject to y(t_0) = y_0. CourseNana.COM

The problem is solved numerical using METHOD from t0 to T using a time step dt. CourseNana.COM

Parameters ---------- CourseNana.COM

np.double , CourseNana.COM

np.double , np.double , CourseNana.COM

rhs CourseNana.COM

T method

Returns ------- CourseNana.COM

t y CourseNana.COM

A function describing the right hand side of the differential equation(s) CourseNana.COM

The starting value of y The starting value of t The time step
The final or stopping time

The method used to advance to solver. method should be one of: CourseNana.COM

Heun , Ralston , Van De Houwen , SSPRK3 , Runge -Kutta , 3/8-rule, Ralston-4 CourseNana.COM

The time points where the solution was found CourseNana.COM

timesteps = CourseNana.COM

# time loop CourseNana.COM

for step in # build CourseNana.COM

int(T / dt) CourseNana.COM

range(timesteps): CourseNana.COM

k’s CourseNana.COM

The estimate of the solution at each time point CourseNana.COM

# set initial data into solution arrays CourseNana.COM

t_out = [t0] y_out = [y0] CourseNana.COM

# extract method helpers CourseNana.COM

matrix , weights , nodes = TABLEAU[method]
s =
k: List[y_type | None] = [None
for _ in range(s)] CourseNana.COM

# count steps CourseNana.COM

for i in range(s):
temp =
sum(matrix[i, j] * k[j] for j in range(i)) k[i] = rhs(t_out[-1] + dt * nodes[i], y_out[-1] + CourseNana.COM

dt * temp)
y_update =
sum([k[i] * weights[i] for i in range(s)]) CourseNana.COM

y_new = y_out[-1] + t_new = t_out[-1] + CourseNana.COM

t_out.append(t_new) y_out.append(y_new) CourseNana.COM

return t_out , y_out CourseNana.COM

def example_code_1(): """ CourseNana.COM

Example code for single CourseNana.COM

dt * y_update dt CourseNana.COM

differential equation CourseNana.COM

The problem is y’(t) = y subject to y(0) = 1.0. CourseNana.COM

The problem is solved with dt = 0.1 until T = 1.0 using CourseNana.COM

Heun’s method CourseNana.COM


""" CourseNana.COM

def rhs1(t: np.double, y: np.double) -> np.double: return -y CourseNana.COM

t, y = solver(rhs1, 1.0, 0.0, 0.1, 1.0, "Heun") CourseNana.COM

def example_code_2(): """ CourseNana.COM

example code for system of differential equations CourseNana.COM

The problem is (x’(t), y’(t)) = (-y(t), x(t)) subject to (x(0), y(0)) = (1.0, 0.0) CourseNana.COM

The problem is solved with dt = 0.1 until T = 1.0 using the Runge -Kutta method CourseNana.COM

""" CourseNana.COM

def rhs2(t: np.double, y: np.ndarray) -> np.ndarray: return np.array([-y[1], y[0]]) CourseNana.COM

t, y = solver(rhs2, np.array([1.0, 0.0]), 0.0, 0.1, 1.0, "Runge -Kutta") CourseNana.COM

if __name__ == "__main__":
for method, (matrix, weights, nodes) in TABLEAU.items(): CourseNana.COM

# test methods are explicit CourseNana.COM

np.testing.assert_almost_equal(np.tril(matrix), matrix) CourseNana.COM

# test methods are consistent CourseNana.COM

np.testing.assert_almost_equal(sum(weights), 1.0) # test dimensions match
n, m = matrix.shape
assert n == m

assert n == len(weights) assert n == len(nodes) CourseNana.COM

example_code_1() example_code_2() CourseNana.COM

Get in Touch with Our Experts

Wechat WeChat
Whatsapp Whatsapp
Leeds代写,COMP2421代写,XJCO2421代写,Numerical computation代写,Python代写,Differential Equations代写,Leeds代编,COMP2421代编,XJCO2421代编,Numerical computation代编,Python代编,Differential Equations代编,Leeds代考,COMP2421代考,XJCO2421代考,Numerical computation代考,Python代考,Differential Equations代考,Leedshelp,COMP2421help,XJCO2421help,Numerical computationhelp,Pythonhelp,Differential Equationshelp,Leeds作业代写,COMP2421作业代写,XJCO2421作业代写,Numerical computation作业代写,Python作业代写,Differential Equations作业代写,Leeds编程代写,COMP2421编程代写,XJCO2421编程代写,Numerical computation编程代写,Python编程代写,Differential Equations编程代写,Leedsprogramming help,COMP2421programming help,XJCO2421programming help,Numerical computationprogramming help,Pythonprogramming help,Differential Equationsprogramming help,Leedsassignment help,COMP2421assignment help,XJCO2421assignment help,Numerical computationassignment help,Pythonassignment help,Differential Equationsassignment help,Leedssolution,COMP2421solution,XJCO2421solution,Numerical computationsolution,Pythonsolution,Differential Equationssolution,