我需要計算并繪制一個函數(shù),它是前兩個導(dǎo)數(shù)。然后,我需要在圖形上繪制原始函數(shù)的最小值和最大值點(diǎn)。我已經(jīng)計算了這些,但不知道如何繪制數(shù)據(jù)。最小/最大點(diǎn)的 x 值是 criticalPoints[]y 值是criticalPointsY[]這是出現(xiàn)錯誤的代碼段。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();當(dāng)我運(yùn)行程序時,出現(xiàn)此錯誤。`Traceback (most recent call last): File "--------", line 58, in <module> xval=criticalPoints[a];TypeError: 'FiniteSet' object does not support indexing我嘗試在 p 上繪制點(diǎn)并得到不同的錯誤 p.plot(criticalPoints,criticalPointsY);AttributeError: 'Plot' object has no attribute 'plot'有沒有辦法在這個圖上繪制點(diǎn)?(p)
如何用 Sympy 繪制點(diǎn)?
拉風(fēng)的咖菲貓
2021-08-17 11:00:25