我有此代码可将ode转换为laplace形式,但这仅适用于带导数的ode, 你有一个想法如何使我求积分的微分方程吗?
功能: “ def laplace_transform_derivatives(e)” 对衍生产品非常有用 我问是否有人知道如何对积分执行相同的功能?
'''
import sympy as sym
from sympy.abc import s,t,x,y,z
from sympy.integrals import laplace_transform
from sympy import diff
from sympy import exp, cos, integrate
sym.init_printing()
def laplace_transform_derivatives(e):
"""
Evaluate the unevaluted laplace transforms of derivatives
of functions
"""
if isinstance(e, sym.LaplaceTransform):
if isinstance(e.args[0], sym.Derivative):
d, t, s = e.args
n = d.args[1][1]
#n = len(d.args) - 1
return ((s**n) * sym.LaplaceTransform(d.args[0], t, s) -
sum([s**(n-i) * sym.diff(d.args[0], t, i-1).subs(t,
0) for i in range(1, n+1)]))
if isinstance(e, (sym.Add, sym.Mul)):
t = type(e)
return t(*[laplace_transform_derivatives(arg) for arg in e.args])
return e
t = sym.symbols("t", positive=True)
y = sym.Function("y")
ode = y(t).diff(t) - 2 * y(t) - 5*(0.2*(1-y(t))+0.1*integrate(1-y(t)))
sym.Eq(ode)
s, Y = sym.symbols("s, Y", real=True)
L_y = sym.laplace_transform(y(t), t, s)
L_ode = sym.laplace_transform(ode, t, s, noconds=True)
sym.Eq(L_ode)
#print(L)
L_ode_2 = laplace_transform_derivatives(L_ode)
sym.Eq(L_ode_2)
#print(L_2)
L_ode_3 = L_ode_2.subs(L_y, Y)
sym.Eq(L_ode_3)
#print(L_3)
ics = {y(0): 0 }
L_ode_4 = L_ode_3.subs(ics)
sym.Eq(L_ode_4)
Y_sol = sym.solve(L_ode_4, Y)
print(Y_sol)
'''
我想为以下项目做laplace transfprm: 例子:
dy/dt-2y(t)=0.2(1-y(t))+0.1∫(1-y(t))dt