2014-12-03 58 views
0

我想解決這兩個方程的波紋管,我沒有運氣,如果任何人都可以指出我哪裏錯了,那將是非常感謝!試圖求解2個一階微分方程,python

def f(t,alpha): 
    return t*t/(2*alpha) * (1-sqrt(1-4*alpha)) 

def f_1 (t,x,params): 
    alpha=params[0] 
    return [X[1],-((3/f(t,alpha)*X[0]))] 

T=ode_solver() 
T.y_0=[1,0] 
T.function=f_1 
T.scale_abs=[1e-4,1e-4,1e,-5] 
T.error_rel=1e-4 
T.ode_solve(t_span[0,1000],params=[0.001],num_points=1000) 
T.plot_solution(i=0) 

回答

0

嘗試使用scipy。 看看這個例子:

from scipy.integrate import odeint 
from pylab import * # for plotting commands 

def deriv(y,t, alpha): # return derivatives of the array y #edit: put an extra arg 
    #use the arg whatever you want 
    a = -2.0 
    b = -0.1 
    return array([ y[1], a*y[0]+b*y[1] ]) 

time = linspace(0.0,10.0,1000) 
yinit = array([0.0005,0.2]) # initial values 
alpha = 123 #declare the extra(s) agrg 
y = odeint(deriv,yinit,time,args=(alpha,)) #pass the extras args as tuple 
figure() 

plot(time,y[:,0]) # y[:,0] is the first column of y 
xlabel('t') 
ylabel('y') 
show() 

結果: enter image description here

字體:http://bulldog2.redlands.edu/facultyfolder/deweerd/tutorials/Tutorial-ODEs.pdf

一個有趣的鏈接:http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.integrate.ode.html

+0

感謝您對快速回復,將仍用於集成功能工作那已經有另一個功能了?所以在我的情況下,我正在嘗試解決f_1,但在f_1中我有另一個函數f。謝謝! – 2014-12-03 11:45:14

+0

是的。這個內部函數將只是一個數字。 – 2014-12-03 11:51:34

+0

如果我想添加額外的參數,在我的情況下alpha,我將如何去把它放入odeint代碼行?謝謝@JoãoPauloOliveiraFernandes – 2014-12-03 12:55:49