我试图用 matplotlib 和微积分绘制图表,但我的 f(x) 函数的 math.sqrt() 不起作用。我需要平方根 2*x-1。如代码所示
import matplotlib.pyplot as plt
import math
def f(x):
return math.sqrt(2*x-1)
plt.plot([0, 1, 2, 3, 4], [f(0), f(1), f(2), f(3), f(4)])
plt.show()
它给出了一个错误,说 ValueError: math domain error。我不确定如何以正确的方式进行/修复