我想使用Python、numpy和matplotlib绘制一个简单的函数,但是当我执行脚本时,它返回了标题中描述的ValueError错误。
这是我的代码:
"""Geometrical interpretation: In Python, plot the function y = f(x) = x**3 − (1/x)
and plot its tangent line at x = 1 and at x = 2."""
import numpy as np
import matplotlib.pyplot as plt
def plot(func):
plt.figure(figsize=(12, 8))
x = np.linspace(-100, 100, 100)
plt.plot(x, func, '-', color='pink')
plt.show()
plt.close()
plot(lambda x: x ** 3 - (1 / x))
请帮助这位初学者 :)