-
Notifications
You must be signed in to change notification settings - Fork 41
laplace transform of diffrential equation with integral #5
Description
Hello,
i have this code for turn ode to laplace form, but this work only for ode with derivative,
do you have an idea how to make i work for diffrential equation with integral ?
see example below.
'''
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 ((sn) * 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)
'''
example: dy/dt-2y(t)=0.2(1-y(t))+0.1∫(1-y(t))dt
regarsd,
Tomer