求解微分方程Sympy [英] Solving Differential Equation Sympy

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

问题描述

我一直无法找到这个微分方程的特定解.

from sympy import *m = float(raw_input('质量:\n>'))克 = 9.8k = float(raw_input('阻力系数:\n>'))v = 函数('v')f1 = g * mt = Symbol('t')v = 函数('v')方程 = dsolve(f1 - k * v(t) - m * Derivative(v(t)), 0)打印方程

对于 m = 1000 和 k = .2,它返回

Eq(f(t), C1*exp(-0.0002*t) + 49000.0)

这是正确的,但我想要求解当 v(0) = 0 时应该返回的方程

Eq(f(t), 49000*(1-exp(-0.0002*t))

解决方案

我相信 Sympy 还不能考虑初始条件.尽管 dsolve 具有用于输入初始条件的选项 ics(请参阅文档),但它似乎用途有限.

因此,您需要手动应用初始条件.例如:

C1 = Symbol('C1')C1_ic = solve(equation.rhs.subs({t:0}),C1)[0]打印 equation.subs({C1:C1_ic})

<块引用>

Eq(v(t), 49000.0 - 49000.0*exp(-0.0002*t))

I haven't been able to find particular solutions to this differential equation.

from sympy import *

m = float(raw_input('Mass:\n> '))
g = 9.8
k = float(raw_input('Drag Coefficient:\n> '))
v = Function('v')
f1 = g * m
t = Symbol('t')
v = Function('v')
equation = dsolve(f1 - k * v(t) - m * Derivative(v(t)), 0)
print equation

for m = 1000 and k = .2 it returns

Eq(f(t), C1*exp(-0.0002*t) + 49000.0)

which is correct but I want the equation solved for when v(0) = 0 which should return

Eq(f(t), 49000*(1-exp(-0.0002*t))

解决方案

I believe Sympy is not yet able to take into account initial conditions. Although dsolve has the option ics for entering initial conditions (see the documentation), it appears to be of limited use.

Therefore, you need to apply the initial conditions manually. For example:

C1 = Symbol('C1')
C1_ic = solve(equation.rhs.subs({t:0}),C1)[0]

print equation.subs({C1:C1_ic})

Eq(v(t), 49000.0 - 49000.0*exp(-0.0002*t))

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

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