1
0
Fork 0
Browse Source

Ex1.a added

master
Eric Teunis de Boone 3 years ago
parent
commit
9268f96ac9
  1. 2
      README.md
  2. 36
      week1/ex1.py
  3. BIN
      week1/week1.pdf

2
README.md

@ -1,3 +1,3 @@
# cds-numerical-methods
Coursework CDS:Numerical Methods
Coursework CDS:Numerical Methods 2019-2020

36
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

BIN
week1/week1.pdf

Binary file not shown.