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

1 Assignment A2

This is the second individual assignment for MATH08065 Computing and Numerics.

Your code should be clear, easy to understand, and commented as necessary. You should choose which output and/or plots your code should generate for each question, and should use the output and/or plots to support your discussion where appropriate. Any plots must be well laid out and clearly labelled.

Your code and discussions should be pitched at an appropriate level, based on concepts and principles as introduced in the course materials. Marks may be reduced for excessively verbose or overly technical implementations or discussions, or for excessively commented or overly documented code.

Marks may be significantly reduced for discussions which do not align with associated code or output. Marks may be reduced for poor scholarship.

1.0.1 Citations

If you make use of external sources then these must be indicated with an appropriate citation. You may also wish to support your discussions through the use of appropriate citations.

Typical citation format (include as many elements as possible):

• Websites: Title, author(s), url, access date.
• Generative AI: Tool, use date, prompts, output.
• Textbooks: Title, author(s), editor(s), publisher, year.
• Journal articles: Title, author(s), journal, volume, pages, year.

1.0.2 Generative AI

Generative AI must be treated as an external source. If any idea, code, text, or other content originates from generative AI, and is not your own work, this must be clearly identified and cited. If in doubt please discuss with the course organizer.

1.0.3 Submission

1. Make sure you run all the cells in your A2.ipynb notebook, in particular so that any output is displayed in the notebook.

2. Submit your A2.ipynb file to Gradescope. If working on Noteable open your notebook, then use ‘File’->‘Download’ to download the Notebook file. You can then upload this to Gradescope.

11.1 Question 1: Numerical differentiation

1.1 The following code computes approximations for sin x and cos x, assuming x is an integer or floating point input, and that atol and rtol are floating point inputs. Add detailed commentsthroughout the  code explaining how it works.

For this question you should disregard normal advice for commenting, and should instead explain in detail how the code works in the comments. [6 marks]

[ ]: from itertools import count
import numpy as np
def sin(x, *, atol=1e-8, rtol=1e-8):
if atol < 0 or rtol < 0:
raise ValueError("Invalid tolerance")
x = np.mod(float(x) + np.pi, 2 * np.pi) - np.pi
y = 0.
t = x
for i in count(start=1):
y += t
if np.abs(t) <= np.maximum(atol, rtol * np.abs(y)):
return y
t *= -x ** 2 / ((2 * i) * (2 * i + 1))
def cos(x, *, atol=1e-8, rtol=1e-8):
return sin(x + np.pi / 2, atol=atol, rtol=rtol)
1.2 Consider the following approximation for a numerical derivative.


to investigate the accuracy of the derivative approximation, using the sin and cos functions provided in question 1.1 to evaluate sin x and cos x. Summarize your results in a discussion of no more than 200 words. [10 marks]

Discussion

Add discussion here (double click to edit).