python123高次方程求根,试图求解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)

解决方案

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

Result:

10cfc41b440f2d5a28c804670910e433.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值