python如何求解微分方程,如何使用Python内置函数odeint求解微分方程?

在尝试用Python内置函数odeint解决特定微分方程时,遇到了结果与预期不符的问题。经过分析,发现错误包括方程的符号错误、初始条件与积分范围不匹配以及函数定义不正确。修正这些错误后,调整积分范围以避免奇异点,并将两次积分结果合并,最终得到与预期相符的解答。
摘要由CSDN通过智能技术生成

I want to solve this differential equations with the given initial conditions:

(3x-1)y''-(3x+2)y'+(6x-8)y=0, y(0)=2, y'(0)=3

the ans should be

y=2*exp(2*x)-x*exp(-x)

here is my code:

def g(y,x):

y0 = y[0]

y1 = y[1]

y2 = (6*x-8)*y0/(3*x-1)+(3*x+2)*y1/(3*x-1)

return [y1,y2]

init = [2.0, 3.0]

x=np.linspace(-2,2,100)

sol=spi.odeint(g,init,x)

plt.plot(x,sol[:,0])

plt.show()

but what I get is different from the answer.

what have I done wrong?

解决方案

There are several things wrong here. Firstly, your equation is apparently

(3x-1)y''-(3x+2)y'-(6x-8)y=0; y(0)=2, y'(0)=3

(note the sign of the term in y). For this equation, your analytical

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值