<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Interpolation Exercise 1
Step1:  2D trajectory interpolation
The file trajectory.npz contains 3 Numpy arrays that describe a 2d trajectory of a particle as a function of time
Step2:  Use these arrays to create interpolated functions $x(t)$ and $y(t)$. Then use those functions to create the following arrays
Step3:  Make a parametric plot of ${x(t),y(t)}$ that shows the interpolated values and the original points
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy.interpolate import interp1d
Explanation: Interpolation Exercise 1
End of explanation
f = np.load("trajectory.npz")
t = f['t']
x = f['x']
y = f['y']
assert isinstance(x, np.ndarray) and len(x)==40
assert isinstance(y, np.ndarray) and len(y)==40
assert isinstance(t, np.ndarray) and len(t)==40
Explanation: 2D trajectory interpolation
The file trajectory.npz contains 3 Numpy arrays that describe a 2d trajectory of a particle as a function of time:
t which has discrete values of time t[i].
x which has values of the x position at those times: x[i] = x(t[i]).
x which has values of the y position at those times: y[i] = y(t[i]).
Load those arrays into this notebook and save them as variables x, y and t:
End of explanation
X = interp1d(t, x, kind='cubic')
Y = interp1d(t, y, kind='cubic')
newt = np.linspace(min(t), max(t), 200)
newx = X(newt)
newy = Y(newt)
assert newt[0]==t.min()
assert newt[-1]==t.max()
assert len(newt)==200
assert len(newx)==200
assert len(newy)==200
Explanation: Use these arrays to create interpolated functions $x(t)$ and $y(t)$. Then use those functions to create the following arrays:
newt which has 200 points between ${t_{min},t_{max}}$.
newx which has the interpolated values of $x(t)$ at those times.
newy which has the interpolated values of $y(t)$ at those times.
End of explanation
plt.figure(figsize=(12,5))
plt.plot(t, x, 'b', linestyle='', marker='o', label="Original Point for x(t)")
plt.plot(t, y, 'r', linestyle = '', marker='o', label="Original Point for y(t)")
plt.plot(newt, newx, 'c-', label="Interpoled x(t)")
plt.plot(newt, newy, 'm-', label="Interpoled y(t)")
plt.grid(False)
ax = plt.gca()
ax.set_axis_bgcolor("white")
plt.xlabel("Time", fontsize=14)
plt.title("X and Y Trajectory", fontsize = 14)
plt.ylabel("Position", fontsize = 14)
plt.legend()
plt.show()
assert True # leave this to grade the trajectory plot
Explanation: Make a parametric plot of ${x(t),y(t)}$ that shows the interpolated values and the original points:
For the interpolated points, use a solid line.
For the original points, use circles of a different color and no line.
Customize you plot to make it effective and beautiful.
End of explanation
<END_TASK>