Skip to content

laplace transform of diffrential equation with integral #5

Open

Description

@machine85

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

Activity

  1. APMonitor commented on Jun 24, 2019

    @APMonitor
    Owner

    The Laplace transform of an integral is X(s)/s as shown in the Laplace tables: http://apmonitor.com/pdc/index.php/Main/LaplaceTransforms If sympy isn't working like you expect, I'd recommend that you reach out to the Sympy community for support. Sorry that I can't help more with this.

  2. machine85 commented on Jun 24, 2019

    @machine85
    Author

    ok thanks,
    the code that i aded didn't paste well,
    so i atached a file,
    i think that it a very usefull code for ode
    ode_to_laplace.txt

    thank for your help,
    Tomer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions