我需要计算并绘制一个函数,它是前两个导数。然后,我需要在图形上绘制原始函数的最小值和最大值点。我已经计算了这些,但不知道如何绘制数据。最小/最大点的 x 值是 criticalPoints[]
y 值是
criticalPointsY[]
这是出现错误的代码段。
equation=CreateFunction();
firstDeriv=equation.diff(x);
secondDeriv=firstDeriv.diff(x);
print(equation);
criticalPoints=solveset(firstDeriv,x);
criticalPointsY=[];
for a in criticalPoints:
criticalPointsY.append(equation.subs(x,a));
p=plot(equation,firstDeriv,secondDeriv,(x,-10,10));
# Need to add the critical points to the graph. We have them, and the
# y values, but need to put them on the graphs.
print(criticalPoints)
print(criticalPointsY);
for a in range(0, len(criticalPoints)):
xval=criticalPoints[a];
yval=criticalPointsY[a];
plt.plot(xval, yval, 'ro')
p.show();
plt.show();
当我运行程序时,出现此错误。`
Traceback (most recent call last):
File "--------", line 58, in <module>
xval=criticalPoints[a];
TypeError: 'FiniteSet' object does not support indexing
我尝试在 p 上绘制点并得到不同的错误
p.plot(criticalPoints,criticalPointsY);
AttributeError: 'Plot' object has no attribute 'plot'
有没有办法在这个图上绘制点?(p)
相关分类