我想在python中把以下y和y'函式一起繪制在同一軸上。X軸的數值應該從-10到10,間隔為0.1。
我所嘗試的。 我試著只繪制y'(標記為y_p),但我得到了錯誤。
import numpy as np
import matplotlib.pyplot as plt
x = np.range(-10,10, 0.1)
A=1,1
B=0.1
C=0.1
y_p = (A*np.exp((-x**2)/2))(1 (B*( (2*( np. sqrt(2))*(x**3))-(3*(np. sqrt(2))*x)/((np.sqrt(6))))))
plt.plot(x,y_p)
但這產生了錯誤:
TypeError Traceback (most recent call last)
<ipython-input-71-c184f15d17c7> in < module>
7 B=0.1
8 C=0.1
----> 9 y_p = (A*np. exp((-x**2)/2))(1 (B*( (2*( np. sqrt(2))*(x**3))-(3*(np. sqrt(2))*x)/((np.sqrt(6))))))
10 plt.plot(x,y_p)
型別錯誤。'numpy.ndarray' object is not callable
我相信有一個更好的方法可以做到這一點。我對Python很陌生,所以非常感謝任何幫助!
uj5u.com熱心網友回復:
適當的方法是一步一步來:
你可以先把y1定義為一個lambda:
y1 = lambda x: (2*np. sqrt(2)*x**3 - 3*np.sqrt(2)*x) /np.sqrt(6)
然后實作你的公式:
y_p = A * np.exp(-x**2/2)*(1 B*y1(x))
這樣一來,你就有更少的機會得到一個錯字。
uj5u.com熱心網友回復:
在python中,你不能進行隱式乘法(不使用*)。
這是修正后的代碼:
importmatplotlib.pyplot as plt
import numpy as np
x = np.range(-10, 10, 0.1)
A=1,1。
B = 0.1
C =0.1
y_p = (A * np.exp((-x ** 2) / 2) * (1 (B * ((2 * (np.sqrt(2) * (x ** 3)) - (3 * (np.sqrt(2) ) * x)) / (np.sqrt(6)))))
plt.plot(x, y_p)
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/326850.html
標籤:
下一篇:定義陣列而不分配它
