diff --git a/README.md b/README.md index 8da635e..4ded7ec 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # cds-numerical-methods -Coursework CDS:Numerical Methods \ No newline at end of file +Coursework CDS:Numerical Methods 2019-2020 diff --git a/week1/ex1.py b/week1/ex1.py new file mode 100644 index 0000000..cde4bfe --- /dev/null +++ b/week1/ex1.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import numpy as np +import matplotlib.pyplot as plt + + +# Truncation of Euler's Constant +e_OEIS = 2.7182818284590452353 +N_max = 25 +N_range = np.arange(0, N_max) + +# a) Simple Relative Error Determine +e_approx = np.zeros(N_max) +rel_err = np.zeros(N_max) + +prev_e = 0 +for i, n in enumerate(N_range): + e_approx[i] = prev_e + 1/np.math.factorial(n) + + rel_err[i] = abs( e_approx[i] - e_OEIS ) / e_OEIS + prev_e = e_approx[i] + +print(e_approx) + +fig, ax = plt.subplots() +ax.plot(N_range, rel_err) +ax.set_yscale('log') +ax.grid() +ax.set_ylabel("Relative Error") +ax.set_xlabel("N") + +plt.show() + + +# b) Varying Floating Point Precision + diff --git a/week1/week1.pdf b/week1/week1.pdf new file mode 100644 index 0000000..1531080 Binary files /dev/null and b/week1/week1.pdf differ