考虑这个python脚本
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,1,100)
def y(x,z):
return x**2 + z**-1 - 1
for z in np.arange(1,50,1):
plt.plot(x, y(x,z))
在固定的x,我该如何绘制
plt.plot(z, y(x,z))
plt.plot(z, y(x,z).derivative) #dy/dz
答案 0 :(得分:1)
您必须使用derivative
功能:
import numpy as np
import matplotlib.pyplot as plt
from scipy.misc import derivative
x = np.linspace(0,1,100)
def y(z, x):
return x**2 + z**(-1) - 1
z = np.arange(1.0, 50.0)
dydz = [derivative(y, zi, args=(x, )) for zi in z]
plt.plot(z, dydz)
plt.show()
截图: