试图求解2个一阶微分方程,python [英] trying to solve 2 first order differential equations, python

查看:336
本文介绍了试图求解2个一阶微分方程,python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面,我试图解决这两个方程式,但是我没有运气,如果有人能指出我要去哪里,那将非常感谢!

I am trying to solve these 2 equations bellow and I am having no luck, if anyone can point out where i am going wrong that would be great thanks!

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)

推荐答案

尝试使用scipy. 看这个例子:

Try using scipy. Look this example:

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()

结果:

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

一个有趣的链接: http ://docs.scipy.org/doc/scipy-0.14.0/reference/generation/scipy.integrate.ode.html

这篇关于试图求解2个一阶微分方程,python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆