例1 下边绘制出函数f(x) = sinx+sin1/2x+sin1/3x+sin1/4x在[0,2PI]之间的图形
import numpy as np
import matplotlib.pyplot as plt
import math
x = np.linspace(0,2*math.pi,50)
def f(x):
return np.sin(x) + np.sin(1/2*x) + np.sin(1/3*x) + np.sin(1/4*x)
y = f(x)
plt.plot(x,y)
plt.title('function curve')
plt.show()
例2 求解下边的线性方程组
import numpy as np
A = np.array([[1,2,-3],[3,-1,5],[2,1,1]])
C = np.array([5,2,4])
X = np.linalg.solve(A,C)
print(X)
numpy作图应用
import numpy as np
import matplotlib.pyplot as plt
image = np.random.rand(30,30)
plt.imshow(image, cmap=plt.cm.hot)
plt.colorbar()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)