绘制函数$y = f(x) = x^3 - \frac{1}{x}$和其在$x = 1$处切线的图像

绘制函数 y = f ( x ) = x 3 − 1 x y = f(x) = x^3 - \frac{1}{x} y=f(x)=x3x1和其在 x = 1 x = 1 x=1处切线的图像

from matplotlib import pyplot as plt
def f(x):
    return x**3-1/x
x = np.arange(0, 3, 0.1)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.plot(x, f(x),"-")
plt.plot(x, 4 * x - 4,"--")
plt.legend(['f(x)', 'Tangent line (x=1)'])
plt.show()

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_39107270/article/details/123604471
今日推荐