2014-11-25 142 views
0

我有一個物理問題,從來沒有使用odeint或任何數值求解python ODE,我有點困惑。我試着看其他的例子,但不明白,希望有一點幫助。我的ODE是:需要幫助解決數值ODE [Python]

enter image description here

其中,α是一個給定的角度和g是常數。

R = SQRT(X^2 + Y^2)

程序將詢問X_0,DX/dt_0和dy/dt_0。

我大多不確定如何解決python中的ODE。我已經看到,我應該將我的ODE分割成dr'/ dt,因爲odeint只會執行一階ODE。有人可以幫助解釋如何做到這一點?

我試着用另一個例子做盡可能多的,但我堅持:

import numpy as np 
import matplotlib.pylab as plt 
from scipy.integrate import odeint 

pi=np.pi 
sin=np.sin 
cos=np.cos 
sqrt=np.sqrt 
alpha=pi/4 
g=9.80665 
y0=0.0 
theta0=0.0 

x=[] 
y=[] 
sina = sin(alpha)**2 
second_term = g*sin(alpha)*cos(alpha) 

x0 = float(raw_input('What is the initial x in meters?')) 
x_vel0 = float(raw_input('What is the initial velocity in the x direction in m/s?')) 
y_vel0 = float(raw_input('what is the initial velocity in the y direction in m/s?')) 
t_f = float(raw_input('What is the maximum time in seconds?')) 

r0 = x0 
r = sqrt(float(x)**2 + float(y)**2) 

def deriv_z(z,r): 
    r, rdot=z 
    return [rdot,r*sina-second_term] 
zdot0=x_vel0**2+y_vel0**2 
z0 = [r0,zdot0] 
times = np.linespace(0, t_f, 1000) 

z = odeint(deriv_z,z0,times) 
+0

[解出方程式]的可能重複(http://stackoverflow.com/questions/27154607/working-out-an-equation) – 2014-11-30 23:19:23

回答

-1

有一個great example我發現幫我行星軌道ODE解決。

它使用自適應步長解算器並很好地繪製軌道。如果你的解決方案可以處理它,你也可以嘗試使用更快的'lsoda'或'vode'選項來代替'dopri5'(這是一個非常可靠的標準)。