Exercise 11.1: Plotting a function Plot the function
f(x) = sin2(x - 2)ex2 over the interval [0,2]. Add proper axis labels, a title, etc.
import numpy as np
import matplotlib.pyplot as plt
f,ax= plt.subplots(1,1,figsize = (5,4))
x = np.linspace(0,2,100)
tmp1 = np.sin(x-2)
#计算sin^2(x-2)
f1 = np.power(tmp1,2)
#计算e^(-x^2)
f2 = np.power(np.e,-1 * np.power(x,2))
y = np.multiply(f1,f2)
ax.plot(x,y)
# ax.set_xlim((0,2))
# ax.set_ylim((0,1))
ax.set_xlabel("x label")
ax.set_ylabel("y label")
ax.set_title("f(x) = $sin^2(x-2){e^{-x^2}}$")
plt.tight_layout()
plt.show()
Output: