Sunteți pe pagina 1din 3

Individual Assignment A2

This assessment is marked out of 45 and comprises 40% of the final course mark.

Due by 1700 on Thursday week 12 (1700 on Thursday 11th April).

Academic misconduct
The assessment is primarily summative in nature. You are expected to be aware of and abide by University policies on academic
misconduct.

School of Mathematics academic misconduct advice and policies


Academic Services academic misconduct information

This is an individual assignment - do not copy the work of another student.

If you use any resources (e.g. textbooks or websites) then include appropriate references in your solutions. Course materials do not
need to be referenced.

Markdown
In workshops you have edited Jupyter Notebook "code" cells. Cells can also contain formatted text in "markdown" cells. Some
questions ask for further discussion and explanation, which should be provided in appropriate markdown cells. You may wish to use
formatting features of markdown cells, although this is optional.

Jupyter Notebook: Markdown cells

You can edit markdown cells (e.g the cell initially containing "Discussion for question 1.1" in question 1) by double clicking on them,
and render the markdown by selecting the cell and pressing Shift+Return.

Code commentary
Your code should be extensively commented, with the functionality of each line of code explained with a comment. This is to test your
understanding of the code you have written. Up to half of the marks associated with the coding part of a question may be deducted
for a missing, incomplete, or inaccurate code commentary.

The following provides an example of the expected level of commenting.

In [ ]:
def is_prime(n):
"""
Return whether an input positive integer is prime.
"""

if n == 1: # If n is 1 ...
return False # ... then n is not prime

for i in range(2, n): # Test integers i from 2 to n - 1 inclusive


if n % i == 0: # If n is divisible by i ...
return False # ... then n is not prime
# If n is not divisible by any integers from 2 to n - 1 inclusive then n is
# prime
return True

Output and figures


Your code must generate and display all relevant output when run, and all figure formatting must be performed programmatically and
not via the interactive plotting interface.

Rerun your code cells after editing your code, to make sure that the output is updated.

Saving your work


When you edit the notebook, before closing the window/tab make sure to select "File"->"Save and Checkpoint". If using Noteable
make sure you also download and keep a copy of the edited file, using "File"->"Download as"->"Notebook".
make sure you also download and keep a copy of the edited file, using "File"->"Download as"->"Notebook".

On lab computers make sure you save edited notebook files in an appropriate location, as otherwise they may be lost when you
logout.

Information Services: Saving your files

Question 1: Area of a triangle


For further relevant discussion on computing the area of a triangle see

W. Kahan, Miscalculating area and angles of a needle-like triangle

2
Consider a triangle in R whose vertices have coordinates
( ) ( ) ( )( ) (
x0, y0 = (1, 1), x1, y1 = 2 + 1ε, 2 + 1ε , x2, y2 = 2 − 2ε1 + ε, 2 + 2ε1 + ε , )
where ε is some positive real value.

The area of a triangle can be computed using Heron's formula (see section 1 of W. Kahan, referenced above)
A = √s(s − a)(s − b)(s − c) ,

where s = (a + b + c)/2, and a, b, and c are the lengths of the three sides of the triangle.

1.1 Compute the area of the above triangle using Heron's formula and floating point arithmetic, for different values of ε. Investigate
and discuss what happens for small values of ε. Investigate other ways of computing the area of the triangle.

Summarise and explain your results in a discussion of no more than 350 words.

Your code should be well laid out and easy to understand. You should make appropriate use of output and plots.

[10 marks]

In [ ]:
# Code for question 1.1

Discussion for question 1.1

Question 2: Numerical integration


Throughout this question we consider Chebyshev polynomials, and quadrature rules, defined on the reference interval x ∈ [−1, 1].

2.1 The degree p Chebyshev points are the roots of the degree p Chebyshev polynomial. Write a function which accepts a positive
integer p, defining the Chebyshev polynomial degree, and returns the degree p Chebyshev points, as a NumPy vector. You may wish
to make use of functionality provided by the following NumPy module

NumPy: numpy.polynomials.chebyshev

[2 marks]

{
Hint: For p = 3 the Chebyshev points are − √3/2, 0, √3/2 . }
2.2 Find the quadrature weights wi (for i ∈ {1, …, p}) associated with interpolatory quadrature rules whose quadrature points xi are
the associated degree p Chebyshev points, for different values of p.

Test the quadrature rule obtained for p = 3 by using it to approximate


∫ (1 + cos(πx))2dx,
1−1

and compare the result against the exact value, obtained using SymPy.

[7 marks]

2.3 Investigate the accuracy of the quadrature rules obtained for different values of p.

Summarise and explain your results in a discussion of no more than 250 words.

[7 marks]

Your code should be well laid out and easy to understand. You should make appropriate use of displayed output and plots.
Your code should be well laid out and easy to understand. You should make appropriate use of displayed output and plots.

In [ ]:
# Code for questions 2.1--2.3

Discussion for question 2.3

Question 3: Root finding


Consider the function
3 3
F(x) = x cos(x) − x 10 .

3.1 Plot this function on the intervals x ∈ [−0.5, 1.5] and x ∈ [−0.5, 5]. Use the SciPy optimize.fsolve function to find values for
the roots of F(x) in the interval x ∈ [−0.5, 5].

Your code should be well laid out and easy to understand. Your plots should be appropriately formatted. You should make
appropriate use of displayed output.

[4 marks]

In [ ]:
# Code for question 3.1

3.2 Use Newton's method, and two other root finding methods, to seek the roots of F(x) in the interval x ∈ [−0.5, 5], identified in
question 3.1.

Investigate the convergence properties of Newton's method for this problem, for each of the roots, and compare this against the
convergence properties of the other methods.

Summarise and explain your results in a discussion of no more than 500 words.

Your code should be well laid out and easy to understand. You should make appropriate use of displayed output and plots.

[15 marks]

In [1]:
# Code for question 3.2

Discussion for question 3.2

S-ar putea să vă placă și