Solving Differential Equation Sympy

天大地大妈咪最大 提交于 2019-12-23 12:02:36

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/38950163/solving-differential-equation-sympy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!