Week 1.5: Programming Tutorial

No description has been provided for this image No description has been provided for this image

CEGM1000 MUDE: Week 1.6. October 7, 2024.

This notebook was prepared by Berend Bouvy and used in an in-class demonstration on Monday.

Objects

In [8]:
import numpy as np
import matplotlib.pyplot as plt
from func import *
import timeit
In [6]:
# import data 
data = np.loadtxt('data.txt')
x = data[:,0]
y = data[:,1]
In [ ]:
A = #TODO: create the matrix A
x_hat, y_hat = #TODO: solve the system of equations
print(f"x_hat = {x_hat}")
In [9]:
# runtimes

funcs = [FD_1, FD_2, FD_3, FD_4]

assert np.allclose(funcs[0](x, y), funcs[1](x,y)), "FD_1 and FD_2 are not equal"
assert np.allclose(funcs[0](x, y), funcs[2](x,y)), "FD_1 and FD_3 are not equal"
assert np.allclose(funcs[0](x, y), funcs[3](x,y)), "FD_1 and FD_4 are not equal"

runtime = np.zeros(4)
for i in range(4):
    runtime[i] = timeit.timeit(lambda: funcs[i](x, y), number=1000)

print(f"runtimes: {runtime}")
runtimes: [0.0036198 0.079353  0.0814436 0.0611185]

End of notebook.

© Copyright 2024 MUDE TU Delft. This work is licensed under a CC BY 4.0 License.