11.1
import numpy as np
import matplotlib.pyplot as pltdef func(x):
return (np.sin(x-2)**2)*np.exp(-x**2)
x=np.linspace(0,2,100)
plt.figure(figsize=(8,4))
plt.plot(x,func(x),label='$y=sin^2(x-2)*exp(-x^2)$',color='r',linewidth=0.5)
plt.xlabel('x',size=13)
plt.ylabel('y',size=13)
plt.title('pyplot',size=13)
plt.xlim(0,2)
plt.ylim(-0.5,1.5)
plt.legend()
plt.show()
11.2
import numpy as np
import matplotlib.pyplot as plt
X=np.random.randn(20,10)
b=np.random.randn(10)
z=np.random.randn(20)
x=np.arange(10)
y=np.dot(X,b)+z
b1=np.linalg.lstsq(X,y,rcond=-1)[0]
b1=np.array(b1)
plt.scatter(x,b,color='blue',label='true b')
plt.scatter(x,b1,color='red',label='estimated b')
plt.legend()
plt.show()
11.3
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
z=np.random.randn(10000,1)
sns.distplot(z,bins=25,kde=True)
plt.ylim(0,0.5)
plt.show()