Write a function called fourier which takes input parameters c and num where c is a Python list of numbers c = [c1, c2, ..., cN] and num is a positive integer. The function fourier plots the function
f(x) = 2 * Σ(c[k] * cos(k * x))
over the interval [0, 1] using num equally spaced points from 0 to 1. In other words, use np.linspace(0, 1, num) for the x values. The function also returns the x and y values of the plot in a matrix with 2 columns, with x values in the first column and y values in the second. The function np.column_stack may be helpful. (Note that the function is a (partial) Fourier cosine series.)
For example:
fourier([1, 2, 4, 8, 16], 100)
creates the figure:
20
10
-10
20
0.0
0.2
0.4
0.6
0.8
10
In []: # YOUR CODE HERE
In []: # Check fourier returns the correct datatype.
assert isinstance(fourier([1, 1, 5, 1, 5], 200), np.ndarray), "Return value should be a NumPy array."
print("Problem 2 Test 1: Success!")
In []: # Check fourier returns the correct size of NumPy array.
print("Problem 2 Test 2: Success!")
In []: # Check fourier returns the correct values.
epsilon = 1e-8
M = fourier([1, -1, 2, -1, 1], 200)
ans1 = np.array([[0., 1.5], [0.00502513, 1.49303019], [0.01005025, 1.47222285]])
ans2 = np.array([[0.98994975, 1.47222285], [0.99497487, 1.49303019], [1., 1.5]])
ans3 = np.array([[0.98994975, 1.47222285], [0.99497487, 1.49303019], [1., 1.5]])
assert np.max(np.abs(M[:3, :] - ans1)) < epsilon
assert np.max(np.abs(M[100:103, :] - ans2)) < epsilon
assert np.max(np.abs(M[-3, :] - ans3)) < epsilon
print("Problem 2 Test 3: Success!")