ex 1
import matplotlib.pyplot as plt
import math
import numpy as np
x = np.linspace(0, 5, 100)
y1=np.sin((x-2))**2
y2=math.e**(-1*x**2)
y = y1*y2
plt.figure()
plt.plot(x, y, 'b')
plt.xlabel('x')
plt.ylabel('y')
plt.title('f(x) = ${sin2(x − 2)}e−x2$')
plt.axis([0,2, 0, 1])
plt.show()
ex 2
import matplotlib.pyplot as plt
import math
from scipy import linalg
import numpy as np
'''生成数据'''
X = np.random.randint(0, 10, 200).reshape(20, 10)
b = np.random.randint(5, 15, 10).reshape(10, 1)
z = np.random.normal(size = 20).reshape(20, 1)
Y = np.dot(X, b) + z
b_ = np.linalg.lstsq(X, Y, rcond=None)[0]
'''画图'''
index = list(range(10))
plt.scatter(index, b, label='True coefficients', color='y', marker='+')
plt.scatter(index, b_, label='Estimated coefficients', color='blue', marker='.')
plt.xlabel('index')
plt.ylabel('value')
plt.legend()
plt.show()
ex 3
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import gaussian_kde
A = np.random.normal(loc = 1000, scale =100 , size = 10000)
A = sorted(A)
kernel = gaussian_kde(A)
plt.hist(A, bins=25, density=True, facecolor='blue', edgecolor='black')
plt.plot(A, kernel.pdf(A))
plt.show()
![](https://i-blog.csdnimg.cn/blog_migrate/49b29700a6055695ec7d4fd1141ae496.png)