예제 #1
0
def test_as_integral():
    from sympy import Function, Integral

    f = Function("f")
    assert mellin_transform(f(x), x, s).rewrite("Integral") == Integral(
        x ** (s - 1) * f(x), (x, 0, oo)
    )
    assert fourier_transform(f(x), x, s).rewrite("Integral") == Integral(
        f(x) * exp(-2 * I * pi * s * x), (x, -oo, oo)
    )
    assert laplace_transform(f(x), x, s).rewrite("Integral") == Integral(
        f(x) * exp(-s * x), (x, 0, oo)
    )
    assert (
        str(
            2
            * pi
            * I
            * inverse_mellin_transform(f(s), s, x, (a, b)).rewrite("Integral")
        )
        == "Integral(x**(-s)*f(s), (s, _c - oo*I, _c + oo*I))"
    )
    assert (
        str(2 * pi * I * inverse_laplace_transform(f(s), s, x).rewrite("Integral"))
        == "Integral(f(s)*exp(s*x), (s, _c - oo*I, _c + oo*I))"
    )
    assert inverse_fourier_transform(f(s), s, x).rewrite("Integral") == Integral(
        f(s) * exp(2 * I * pi * s * x), (s, -oo, oo)
    )
예제 #2
0
def test_issue_7173():
    assert laplace_transform(sinh(a*x)*cosh(a*x), x, s) == \
        (a/(s**2 - 4*a**2), 0,
        And(Or(Abs(periodic_argument(exp_polar(I*pi)*polar_lift(a), oo)) <
        pi/2, Abs(periodic_argument(exp_polar(I*pi)*polar_lift(a), oo)) <=
        pi/2), Or(Abs(periodic_argument(a, oo)) < pi/2,
        Abs(periodic_argument(a, oo)) <= pi/2)))
예제 #3
0
def test_issue_14692():
    b = Symbol("b", negative=True)
    assert laplace_transform(1 / (I * x - b), x, s) == (
        -I * exp(I * b * s) * expint(1, b * s * exp_polar(I * pi / 2)),
        0,
        True,
    )
예제 #4
0
def test_issue_7173():
    assert laplace_transform(sinh(a*x)*cosh(a*x), x, s) == \
        (a/(s**2 - 4*a**2), 0,
        And(Or(Abs(periodic_argument(exp_polar(I*pi)*polar_lift(a), oo)) <
        pi/2, Abs(periodic_argument(exp_polar(I*pi)*polar_lift(a), oo)) <=
        pi/2), Or(Abs(periodic_argument(a, oo)) < pi/2,
        Abs(periodic_argument(a, oo)) <= pi/2)))
예제 #5
0
def test_expint():
    from sympy.functions.elementary.miscellaneous import Max
    from sympy.functions.special.error_functions import (Ci, E1, Ei, Si)
    from sympy.functions.special.zeta_functions import lerchphi
    from sympy.simplify.simplify import simplify
    aneg = Symbol('a', negative=True)
    u = Symbol('u', polar=True)

    assert mellin_transform(E1(x), x, s) == (gamma(s)/s, (0, oo), True)
    assert inverse_mellin_transform(gamma(s)/s, s, x,
              (0, oo)).rewrite(expint).expand() == E1(x)
    assert mellin_transform(expint(a, x), x, s) == \
        (gamma(s)/(a + s - 1), (Max(1 - re(a), 0), oo), True)
    # XXX IMT has hickups with complicated strips ...
    assert simplify(unpolarify(
                    inverse_mellin_transform(gamma(s)/(aneg + s - 1), s, x,
                  (1 - aneg, oo)).rewrite(expint).expand(func=True))) == \
        expint(aneg, x)

    assert mellin_transform(Si(x), x, s) == \
        (-2**s*sqrt(pi)*gamma(s/2 + S.Half)/(
        2*s*gamma(-s/2 + 1)), (-1, 0), True)
    assert inverse_mellin_transform(-2**s*sqrt(pi)*gamma((s + 1)/2)
                                    /(2*s*gamma(-s/2 + 1)), s, x, (-1, 0)) \
        == Si(x)

    assert mellin_transform(Ci(sqrt(x)), x, s) == \
        (-2**(2*s - 1)*sqrt(pi)*gamma(s)/(s*gamma(-s + S.Half)), (0, 1), True)
    assert inverse_mellin_transform(
        -4**s*sqrt(pi)*gamma(s)/(2*s*gamma(-s + S.Half)),
        s, u, (0, 1)).expand() == Ci(sqrt(u))

    # TODO LT of Si, Shi, Chi is a mess ...
    assert laplace_transform(Ci(x), x, s) == (-log(1 + s**2)/2/s, 0, True)
    assert laplace_transform(expint(a, x), x, s) == \
        (lerchphi(s*exp_polar(I*pi), 1, a), 0, re(a) > S.Zero)
    assert laplace_transform(expint(1, x), x, s) == (log(s + 1)/s, 0, True)
    assert laplace_transform(expint(2, x), x, s) == \
        ((s - log(s + 1))/s**2, 0, True)

    assert inverse_laplace_transform(-log(1 + s**2)/2/s, s, u).expand() == \
        Heaviside(u)*Ci(u)
    assert inverse_laplace_transform(log(s + 1)/s, s, x).rewrite(expint) == \
        Heaviside(x)*E1(x)
    assert inverse_laplace_transform((s - log(s + 1))/s**2, s,
                x).rewrite(expint).expand() == \
        (expint(2, x)*Heaviside(x)).rewrite(Ei).rewrite(expint).expand()
예제 #6
0
def test_expint():
    from sympy import E1, expint, Max, re, lerchphi, Symbol, simplify, Si, Ci, Ei

    aneg = Symbol("a", negative=True)
    u = Symbol("u", polar=True)

    assert mellin_transform(E1(x), x, s) == (gamma(s) / s, (0, oo), True)
    assert inverse_mellin_transform(gamma(s) / s, s, x, (0, oo)).rewrite(expint).expand() == E1(x)
    assert mellin_transform(expint(a, x), x, s) == (gamma(s) / (a + s - 1), (Max(1 - re(a), 0), oo), True)
    # XXX IMT has hickups with complicated strips ...
    assert simplify(
        unpolarify(
            inverse_mellin_transform(gamma(s) / (aneg + s - 1), s, x, (1 - aneg, oo)).rewrite(expint).expand(func=True)
        )
    ) == expint(aneg, x)

    assert mellin_transform(Si(x), x, s) == (
        -2 ** s * sqrt(pi) * gamma(s / 2 + S(1) / 2) / (2 * s * gamma(-s / 2 + 1)),
        (-1, 0),
        True,
    )
    assert inverse_mellin_transform(
        -2 ** s * sqrt(pi) * gamma((s + 1) / 2) / (2 * s * gamma(-s / 2 + 1)), s, x, (-1, 0)
    ) == Si(x)

    assert mellin_transform(Ci(sqrt(x)), x, s) == (
        -2 ** (2 * s - 1) * sqrt(pi) * gamma(s) / (s * gamma(-s + S(1) / 2)),
        (0, 1),
        True,
    )
    assert inverse_mellin_transform(
        -4 ** s * sqrt(pi) * gamma(s) / (2 * s * gamma(-s + S(1) / 2)), s, u, (0, 1)
    ).expand() == Ci(sqrt(u))

    # TODO LT of Si, Shi, Chi is a mess ...
    assert laplace_transform(Ci(x), x, s) == (-log(1 + s ** 2) / 2 / s, 0, True)
    assert laplace_transform(expint(a, x), x, s) == (lerchphi(s * polar_lift(-1), 1, a), 0, S(0) < re(a))
    assert laplace_transform(expint(1, x), x, s) == (log(s + 1) / s, 0, True)
    assert laplace_transform(expint(2, x), x, s) == ((s - log(s + 1)) / s ** 2, 0, True)

    assert inverse_laplace_transform(-log(1 + s ** 2) / 2 / s, s, u).expand() == Heaviside(u) * Ci(u)
    assert inverse_laplace_transform(log(s + 1) / s, s, x).rewrite(expint) == Heaviside(x) * E1(x)
    assert (
        inverse_laplace_transform((s - log(s + 1)) / s ** 2, s, x).rewrite(expint).expand()
        == (expint(2, x) * Heaviside(x)).rewrite(Ei).rewrite(expint).expand()
    )
예제 #7
0
def test_undefined_function():
    from sympy import Function, MellinTransform
    f = Function('f')
    assert mellin_transform(f(x), x, s) == MellinTransform(f(x), x, s)
    assert mellin_transform(f(x) + exp(-x), x, s) == \
        (MellinTransform(f(x), x, s) + gamma(s), (0, oo), True)

    assert laplace_transform(2*f(x), x, s) == 2*LaplaceTransform(f(x), x, s)
예제 #8
0
def test_undefined_function():
    from sympy import Function, MellinTransform
    f = Function('f')
    assert mellin_transform(f(x), x, s) == MellinTransform(f(x), x, s)
    assert mellin_transform(f(x) + exp(-x), x, s) == \
        (MellinTransform(f(x), x, s) + gamma(s), (0, oo), True)

    assert laplace_transform(2*f(x), x, s) == 2*LaplaceTransform(f(x), x, s)
예제 #9
0
def test_laplace_transform():
    LT = laplace_transform
    a, b, c, = symbols('a b c', positive=True)
    t = symbols('t')
    w = Symbol("w")
    f = Function("f")

    # Test unevaluated form
    assert laplace_transform(f(t), t, w) == LaplaceTransform(f(t), t, w)
    assert inverse_laplace_transform(f(w), w, t,
                                     plane=0) == InverseLaplaceTransform(
                                         f(w), w, t, 0)

    # test a bug
    spos = symbols('s', positive=True)
    assert LT(exp(t), t, spos)[:2] == (1 / (spos - 1), True)

    # basic tests from wikipedia

    assert LT((t-a)**b*exp(-c*(t-a))*Heaviside(t-a), t, s) \
           == ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True)
    assert LT(t**a, t, s) == (s**(-a - 1) * gamma(a + 1), 0, True)
    assert LT(Heaviside(t), t, s) == (1 / s, 0, True)
    assert LT(Heaviside(t - a), t, s) == (exp(-a * s) / s, 0, True)
    assert LT(1 - exp(-a * t), t, s) == (a / (s * (a + s)), 0, True)

    assert LT((exp(2*t)-1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \
           == exp(-b)/(s**2 - 1)

    assert LT(exp(t), t, s)[:2] == (1 / (s - 1), 1)
    assert LT(exp(2 * t), t, s)[:2] == (1 / (s - 2), 2)
    assert LT(exp(a * t), t, s)[:2] == (1 / (s - a), a)

    assert LT(log(t / a), t,
              s) == ((log(a) + log(s) + EulerGamma) / (-s), 0, True)

    assert LT(erf(t), t, s) == ((-erf(s / 2) + 1) * exp(s**2 / 4) / s, 0, True)

    assert LT(sin(a * t), t, s) == (a / (a**2 + s**2), 0, True)
    assert LT(cos(a * t), t, s) == (s / (a**2 + s**2), 0, True)
    # TODO would be nice to have these come out better
    assert LT(exp(-a * t) * sin(b * t), t,
              s) == (1 / b / (1 + (a + s)**2 / b**2), -a, True)
    assert LT(exp(-a*t)*cos(b*t), t, s) == \
           (1/(s + a)/(1 + b**2/(a + s)**2), -a, True)
    # TODO sinh, cosh have delicate cancellation

    assert LT(besselj(0, t), t, s) == (1 / sqrt(1 + s**2), 0, True)
    assert LT(besselj(1, t), t, s) == (1 - 1 / sqrt(1 + 1 / s**2), 0, True)
    # TODO general order works, but is a *mess*
    # TODO besseli also works, but is an even greater mess

    # test a bug in conditions processing
    # TODO the auxiliary condition should be recognised/simplified
    assert LT(exp(t) * cos(t), t, s)[:-1] in [
        ((s - 1) / (s**2 - 2 * s + 2), -oo),
        ((s - 1) / ((s - 1)**2 + 1), -oo),
    ]
예제 #10
0
def test_expint():
    from sympy import E1, expint, Max, re, lerchphi, Symbol, simplify, Si, Ci, Ei
    aneg = Symbol('a', negative=True)
    u = Symbol('u', polar=True)

    assert mellin_transform(E1(x), x, s) == (gamma(s) / s, (0, oo), True)
    assert inverse_mellin_transform(gamma(s) / s, s, x,
                                    (0, oo)).rewrite(expint).expand() == E1(x)
    assert mellin_transform(expint(a, x), x, s) == \
        (gamma(s)/(a + s - 1), (Max(1 - re(a), 0), oo), True)
    # XXX IMT has hickups with complicated strips ...
    assert simplify(unpolarify(
                    inverse_mellin_transform(gamma(s)/(aneg + s - 1), s, x,
                  (1 - aneg, oo)).rewrite(expint).expand(func=True))) == \
        expint(aneg, x)

    assert mellin_transform(Si(x), x, s) == \
        (-2**s*sqrt(pi)*gamma(s/2 + S(1)/2)/(
        2*s*gamma(-s/2 + 1)), (-1, 0), True)
    assert inverse_mellin_transform(-2**s*sqrt(pi)*gamma((s + 1)/2)
                                    /(2*s*gamma(-s/2 + 1)), s, x, (-1, 0)) \
        == Si(x)

    assert mellin_transform(Ci(sqrt(x)), x, s) == \
        (-2**(2*s - 1)*sqrt(pi)*gamma(s)/(s*gamma(-s + S(1)/2)), (0, 1), True)
    assert inverse_mellin_transform(
        -4**s * sqrt(pi) * gamma(s) / (2 * s * gamma(-s + S(1) / 2)), s, u,
        (0, 1)).expand() == Ci(sqrt(u))

    # TODO LT of Si, Shi, Chi is a mess ...
    assert laplace_transform(Ci(x), x, s) == (-log(1 + s**2) / 2 / s, 0, True)
    assert laplace_transform(expint(a, x), x, s) == \
        (lerchphi(s*polar_lift(-1), 1, a), 0, S(0) < re(a))
    assert laplace_transform(expint(1, x), x, s) == (log(s + 1) / s, 0, True)
    assert laplace_transform(expint(2, x), x, s) == \
        ((s - log(s + 1))/s**2, 0, True)

    assert inverse_laplace_transform(-log(1 + s**2)/2/s, s, u).expand() == \
        Heaviside(u)*Ci(u)
    assert inverse_laplace_transform(log(s + 1)/s, s, x).rewrite(expint) == \
        Heaviside(x)*E1(x)
    assert inverse_laplace_transform((s - log(s + 1))/s**2, s,
                x).rewrite(expint).expand() == \
        (expint(2, x)*Heaviside(x)).rewrite(Ei).rewrite(expint).expand()
예제 #11
0
def test_issue_7173():
    from sympy import cse
    x0, x1, x2, x3 = symbols('x:4')
    ans = laplace_transform(sinh(a * x) * cosh(a * x), x, s)
    r, e = cse(ans)
    assert r == [(x0, arg(a)), (x1, Abs(x0)), (x2, pi / 2), (x3, Abs(x0 + pi))]
    assert e == [
        a / (-4 * a**2 + s**2), 0,
        ((x1 <= x2) | (x1 < x2)) & ((x3 <= x2) | (x3 < x2))
    ]
예제 #12
0
def test_laplace_transform():
    LT = laplace_transform
    a, b, c, = symbols('a b c', positive=True)
    t = symbols('t')
    w = Symbol("w")
    f = Function("f")

    # Test unevaluated form
    assert laplace_transform(f(t), t, w) == LaplaceTransform(f(t), t, w)
    assert inverse_laplace_transform(f(w), w, t, plane=0) == InverseLaplaceTransform(f(w), w, t, 0)

    # test a bug
    spos = symbols('s', positive=True)
    assert LT(exp(t), t, spos)[:2] == (1/(spos - 1), True)

    # basic tests from wikipedia

    assert LT((t-a)**b*exp(-c*(t-a))*Heaviside(t-a), t, s) \
           == ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True)
    assert LT(t**a, t, s) == (s**(-a - 1)*gamma(a + 1), 0, True)
    assert LT(Heaviside(t), t, s) == (1/s, 0, True)
    assert LT(Heaviside(t - a), t, s) == (exp(-a*s)/s, 0, True)
    assert LT(1 - exp(-a*t), t, s) == (a/(s*(a + s)), 0, True)

    assert LT((exp(2*t)-1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \
           == exp(-b)/(s**2 - 1)

    assert LT(exp(t), t, s)[:2] == (1/(s-1), 1)
    assert LT(exp(2*t), t, s)[:2] == (1/(s-2), 2)
    assert LT(exp(a*t), t, s)[:2] == (1/(s-a), a)

    assert LT(log(t/a), t, s) == ((log(a) + log(s) + EulerGamma)/(-s), 0, True)

    assert LT(erf(t), t, s) == ((-erf(s/2) + 1)*exp(s**2/4)/s, 0, True)

    assert LT(sin(a*t), t, s) == (a/(a**2 + s**2), 0, True)
    assert LT(cos(a*t), t, s) == (s/(a**2 + s**2), 0, True)
    # TODO would be nice to have these come out better
    assert LT(exp(-a*t)*sin(b*t), t, s) == (1/b/(1 + (a + s)**2/b**2), -a, True)
    assert LT(exp(-a*t)*cos(b*t), t, s) == \
           (1/(s + a)/(1 + b**2/(a + s)**2), -a, True)
    # TODO sinh, cosh have delicate cancellation

    assert LT(besselj(0, t), t, s) == (1/sqrt(1 + s**2), 0, True)
    assert LT(besselj(1, t), t, s) == (1 - 1/sqrt(1 + 1/s**2), 0, True)
    # TODO general order works, but is a *mess*
    # TODO besseli also works, but is an even greater mess

    # test a bug in conditions processing
    # TODO the auxiliary condition should be recognised/simplified
    assert LT(exp(t)*cos(t), t, s)[:-1] in [
        ((s - 1)/(s**2 - 2*s + 2), -oo),
        ((s - 1)/((s - 1)**2 + 1), -oo),
        ]
예제 #13
0
def test_issue_7173():
    from sympy import cse
    x0, x1, x2 = symbols('x:3')
    ans = laplace_transform(sinh(a*x)*cosh(a*x), x, s)
    r, e = cse(ans)
    assert r == [
        (x0, pi/2),
        (x1, Abs(periodic_argument(a, oo))),
        (x2, Abs(periodic_argument(exp_polar(I*pi)*polar_lift(a), oo)))]
    assert e == [
        a/(-4*a**2 + s**2),
        0,
        ((x0 >= x1) | (x1 < x0)) & ((x0 >= x2) | (x2 < x0))]
예제 #14
0
def test_issue_7173():
    from sympy import cse
    x0, x1, x2 = symbols('x:3')
    ans = laplace_transform(sinh(a * x) * cosh(a * x), x, s)
    r, e = cse(ans)
    assert r == [(x0, pi / 2), (x1, Abs(periodic_argument(a, oo))),
                 (x2,
                  Abs(periodic_argument(exp_polar(I * pi) * polar_lift(a),
                                        oo)))]
    assert e == [
        a / (-4 * a**2 + s**2), 0,
        ((x0 >= x1) | (x1 < x0)) & ((x0 >= x2) | (x2 < x0))
    ]
예제 #15
0
def test_messy():
    from sympy.functions.elementary.complexes import re
    from sympy.functions.elementary.hyperbolic import (acosh, acoth)
    from sympy.functions.elementary.piecewise import Piecewise
    from sympy.functions.elementary.trigonometric import (asin, atan)
    from sympy.functions.special.bessel import besselj
    from sympy.functions.special.error_functions import (Chi, E1, Shi, Si)
    from sympy.integrals.transforms import (fourier_transform,
                                            laplace_transform)
    assert laplace_transform(Si(x), x, s) == ((-atan(s) + pi / 2) / s, 0, True)

    assert laplace_transform(Shi(x), x, s) == (acoth(s) / s, -oo, s**2 > 1)

    # where should the logs be simplified?
    assert laplace_transform(Chi(x), x,
                             s) == ((log(s**(-2)) - log(1 - 1 / s**2)) /
                                    (2 * s), -oo, s**2 > 1)

    # TODO maybe simplify the inequalities? when the simplification
    # allows for generators instead of symbols this will work
    assert laplace_transform(besselj(a, x), x, s)[1:] == \
        (0, (re(a) > -2) & (re(a) > -1))

    # NOTE s < 0 can be done, but argument reduction is not good enough yet
    ans = fourier_transform(besselj(1, x) / x, x, s, noconds=False)
    assert tuple([ans[0].factor(deep=True).expand(), ans[1]]) == \
        (Piecewise((0, (s > 1/(2*pi)) | (s < -1/(2*pi))),
                   (2*sqrt(-4*pi**2*s**2 + 1), True)), s > 0)
    # TODO FT(besselj(0,x)) - conditions are messy (but for acceptable reasons)
    #                       - folding could be better

    assert integrate(E1(x)*besselj(0, x), (x, 0, oo), meijerg=True) == \
        log(1 + sqrt(2))
    assert integrate(E1(x)*besselj(1, x), (x, 0, oo), meijerg=True) == \
        log(S.Half + sqrt(2)/2)

    assert integrate(1/x/sqrt(1 - x**2), x, meijerg=True) == \
        Piecewise((-acosh(1/x), abs(x**(-2)) > 1), (I*asin(1/x), True))
예제 #16
0
def test_issue_7173():
    from sympy import cse
    x0, x1, x2, x3 = symbols('x:4')
    ans = laplace_transform(sinh(a*x)*cosh(a*x), x, s)
    r, e = cse(ans)
    assert r == [
        (x0, pi/2),
        (x1, arg(a)),
        (x2, Abs(x1)),
        (x3, Abs(x1 + pi))]
    assert e == [
        a/(-4*a**2 + s**2),
        0,
        ((x0 >= x2) | (x2 < x0)) & ((x0 >= x3) | (x3 < x0))]
예제 #17
0
def test_as_integral():
    from sympy import Integral
    f = Function('f')
    assert mellin_transform(f(x), x, s).rewrite('Integral') == \
        Integral(x**(s - 1)*f(x), (x, 0, oo))
    assert fourier_transform(f(x), x, s).rewrite('Integral') == \
        Integral(f(x)*exp(-2*I*pi*s*x), (x, -oo, oo))
    assert laplace_transform(f(x), x, s).rewrite('Integral') == \
        Integral(f(x)*exp(-s*x), (x, 0, oo))
    assert str(2*pi*I*inverse_mellin_transform(f(s), s, x, (a, b)).rewrite('Integral')) \
        == "Integral(f(s)/x**s, (s, _c - oo*I, _c + oo*I))"
    assert str(2*pi*I*inverse_laplace_transform(f(s), s, x).rewrite('Integral')) == \
        "Integral(f(s)*exp(s*x), (s, _c - oo*I, _c + oo*I))"
    assert inverse_fourier_transform(f(s), s, x).rewrite('Integral') == \
        Integral(f(s)*exp(2*I*pi*s*x), (s, -oo, oo))
예제 #18
0
def test_as_integral():
    from sympy import Function, Integral
    f = Function('f')
    assert mellin_transform(f(x), x, s).rewrite('Integral') == \
        Integral(x**(s - 1)*f(x), (x, 0, oo))
    assert fourier_transform(f(x), x, s).rewrite('Integral') == \
        Integral(f(x)*exp(-2*I*pi*s*x), (x, -oo, oo))
    assert laplace_transform(f(x), x, s).rewrite('Integral') == \
        Integral(f(x)*exp(-s*x), (x, 0, oo))
    assert str(inverse_mellin_transform(f(s), s, x, (a, b)).rewrite('Integral')) \
        == "Integral(x**(-s)*f(s), (s, _c - oo*I, _c + oo*I))"
    assert str(inverse_laplace_transform(f(s), s, x).rewrite('Integral')) == \
        "Integral(f(s)*exp(s*x), (s, _c - oo*I, _c + oo*I))"
    assert inverse_fourier_transform(f(s), s, x).rewrite('Integral') == \
        Integral(f(s)*exp(2*I*pi*s*x), (s, -oo, oo))
예제 #19
0
def test_laplace_transform():
    from sympy import lowergamma
    from sympy.functions.special.delta_functions import DiracDelta
    from sympy.functions.special.error_functions import (fresnelc, fresnels)
    LT = laplace_transform
    a, b, c, = symbols('a, b, c', positive=True)
    t, w, x = symbols('t, w, x')
    f = Function("f")
    g = Function("g")

    # Test rule-base evaluation according to
    # http://eqworld.ipmnet.ru/en/auxiliary/inttrans/
    # Power-law functions (laplace2.pdf)
    assert LT(a*t+t**2+t**(S(5)/2), t, s) ==\
        (a/s**2 + 2/s**3 + 15*sqrt(pi)/(8*s**(S(7)/2)), 0, True)
    assert LT(b/(t+a), t, s) == (-b*exp(-a*s)*Ei(-a*s), 0, True)
    assert LT(1/sqrt(t+a), t, s) ==\
        (sqrt(pi)*sqrt(1/s)*exp(a*s)*erfc(sqrt(a)*sqrt(s)), 0, True)
    assert LT(sqrt(t)/(t+a), t, s) ==\
        (-pi*sqrt(a)*exp(a*s)*erfc(sqrt(a)*sqrt(s)) + sqrt(pi)*sqrt(1/s),
         0, True)
    assert LT((t+a)**(-S(3)/2), t, s) ==\
        (-2*sqrt(pi)*sqrt(s)*exp(a*s)*erfc(sqrt(a)*sqrt(s)) + 2/sqrt(a),
         0, True)
    assert LT(t**(S(1)/2)*(t+a)**(-1), t, s) ==\
        (-pi*sqrt(a)*exp(a*s)*erfc(sqrt(a)*sqrt(s)) + sqrt(pi)*sqrt(1/s),
         0, True)
    assert LT(1/(a*sqrt(t) + t**(3/2)), t, s) ==\
        (pi*sqrt(a)*exp(a*s)*erfc(sqrt(a)*sqrt(s)), 0, True)
    assert LT((t+a)**b, t, s) ==\
        (s**(-b - 1)*exp(-a*s)*lowergamma(b + 1, a*s), 0, True)
    assert LT(t**5/(t+a), t, s) == (120*a**5*lowergamma(-5, a*s), 0, True)
    # Exponential functions (laplace3.pdf)
    assert LT(exp(t), t, s) == (1/(s - 1), 1, True)
    assert LT(exp(2*t), t, s) == (1/(s - 2), 2, True)
    assert LT(exp(a*t), t, s) == (1/(s - a), a, True)
    assert LT(exp(a*(t-b)), t, s) == (exp(-a*b)/(-a + s), a, True)
    assert LT(t*exp(-a*(t)), t, s) == ((a + s)**(-2), -a, True)
    assert LT(t*exp(-a*(t-b)), t, s) == (exp(a*b)/(a + s)**2, -a, True)
    assert LT(b*t*exp(-a*t), t, s) == (b/(a + s)**2, -a, True)
    assert LT(t**(S(7)/4)*exp(-8*t)/gamma(S(11)/4), t, s) ==\
        ((s + 8)**(-S(11)/4), -8, True)
    assert LT(t**(S(3)/2)*exp(-8*t), t, s) ==\
        (3*sqrt(pi)/(4*(s + 8)**(S(5)/2)), -8, True)
    assert LT(t**a*exp(-a*t), t, s) ==  ((a+s)**(-a-1)*gamma(a+1), -a, True)
    assert LT(b*exp(-a*t**2), t, s) ==\
        (sqrt(pi)*b*exp(s**2/(4*a))*erfc(s/(2*sqrt(a)))/(2*sqrt(a)), 0, True)
    assert LT(exp(-2*t**2), t, s) ==\
        (sqrt(2)*sqrt(pi)*exp(s**2/8)*erfc(sqrt(2)*s/4)/4, 0, True)
    assert LT(b*exp(2*t**2), t, s) == b*LaplaceTransform(exp(2*t**2), t, s)
    assert LT(t*exp(-a*t**2), t, s) ==\
        (1/(2*a) - s*erfc(s/(2*sqrt(a)))/(4*sqrt(pi)*a**(S(3)/2)), 0, True)
    assert LT(exp(-a/t), t, s) ==\
        (2*sqrt(a)*sqrt(1/s)*besselk(1, 2*sqrt(a)*sqrt(s)), 0, True)
    assert LT(sqrt(t)*exp(-a/t), t, s) ==\
        (sqrt(pi)*(2*sqrt(a)*sqrt(s) + 1)*sqrt(s**(-3))*exp(-2*sqrt(a)*\
                                                    sqrt(s))/2, 0, True)
    assert LT(exp(-a/t)/sqrt(t), t, s) ==\
        (sqrt(pi)*sqrt(1/s)*exp(-2*sqrt(a)*sqrt(s)), 0, True)
    assert LT( exp(-a/t)/(t*sqrt(t)), t, s) ==\
        (sqrt(pi)*sqrt(1/a)*exp(-2*sqrt(a)*sqrt(s)), 0, True)
    assert LT(exp(-2*sqrt(a*t)), t, s) ==\
        ( 1/s -sqrt(pi)*sqrt(a) * exp(a/s)*erfc(sqrt(a)*sqrt(1/s))/\
         s**(S(3)/2), 0, True)
    assert LT(exp(-2*sqrt(a*t))/sqrt(t), t, s) == (exp(a/s)*erfc(sqrt(a)*\
        sqrt(1/s))*(sqrt(pi)*sqrt(1/s)), 0, True)
    assert LT(t**4*exp(-2/t), t, s) ==\
        (8*sqrt(2)*(1/s)**(S(5)/2)*besselk(5, 2*sqrt(2)*sqrt(s)), 0, True)
    # Hyperbolic functions (laplace4.pdf)
    assert LT(sinh(a*t), t, s) == (a/(-a**2 + s**2), a, True)
    assert LT(b*sinh(a*t)**2, t, s) == (2*a**2*b/(-4*a**2*s**2 + s**3),
                                        2*a, True)
    # The following line confirms that issue #21202 is solved
    assert LT(cosh(2*t), t, s) == (s/(-4 + s**2), 2, True)
    assert LT(cosh(a*t), t, s) == (s/(-a**2 + s**2), a, True)
    assert LT(cosh(a*t)**2, t, s) == ((-2*a**2 + s**2)/(-4*a**2*s**2 + s**3),
                                      2*a, True)
    assert LT(sinh(x + 3), x, s) == (
        (-s + (s + 1)*exp(6) + 1)*exp(-3)/(s - 1)/(s + 1)/2, 0, Abs(s) > 1)
    # The following line replaces the old test test_issue_7173()
    assert LT(sinh(a*t)*cosh(a*t), t, s) == (a/(-4*a**2 + s**2), 2*a, True)
    assert LT(sinh(a*t)/t, t, s) == (log((a + s)/(-a + s))/2, a, True)
    assert LT(t**(-S(3)/2)*sinh(a*t), t, s) ==\
        (-sqrt(pi)*(sqrt(-a + s) - sqrt(a + s)), a, True)
    assert LT(sinh(2*sqrt(a*t)), t, s) ==\
        (sqrt(pi)*sqrt(a)*exp(a/s)/s**(S(3)/2), 0, True)
    assert LT(sqrt(t)*sinh(2*sqrt(a*t)), t, s) ==\
        (-sqrt(a)/s**2 + sqrt(pi)*(a + s/2)*exp(a/s)*erf(sqrt(a)*\
                                            sqrt(1/s))/s**(S(5)/2), 0, True)
    assert LT(sinh(2*sqrt(a*t))/sqrt(t), t, s) ==\
        (sqrt(pi)*exp(a/s)*erf(sqrt(a)*sqrt(1/s))/sqrt(s), 0, True)
    assert LT(sinh(sqrt(a*t))**2/sqrt(t), t, s) ==\
        (sqrt(pi)*(exp(a/s) - 1)/(2*sqrt(s)), 0, True)
    assert LT(t**(S(3)/7)*cosh(a*t), t, s) ==\
        (((a + s)**(-S(10)/7) + (-a+s)**(-S(10)/7))*gamma(S(10)/7)/2, a, True)
    assert LT(cosh(2*sqrt(a*t)), t, s) ==\
        (sqrt(pi)*sqrt(a)*exp(a/s)*erf(sqrt(a)*sqrt(1/s))/s**(S(3)/2) + 1/s,
         0, True)
    assert LT(sqrt(t)*cosh(2*sqrt(a*t)), t, s) ==\
        (sqrt(pi)*(a + s/2)*exp(a/s)/s**(S(5)/2), 0, True)
    assert LT(cosh(2*sqrt(a*t))/sqrt(t), t, s) ==\
        (sqrt(pi)*exp(a/s)/sqrt(s), 0, True)
    assert LT(cosh(sqrt(a*t))**2/sqrt(t), t, s) ==\
        (sqrt(pi)*(exp(a/s) + 1)/(2*sqrt(s)), 0, True)
    # logarithmic functions (laplace5.pdf)
    assert LT(log(t), t, s) == (-log(s+S.EulerGamma)/s, 0, True)
    assert LT(log(t/a), t, s) == (-log(a*s + S.EulerGamma)/s, 0, True)
    assert LT(log(1+a*t), t, s) == (-exp(s/a)*Ei(-s/a)/s, 0, True)
    assert LT(log(t+a), t, s) == ((log(a) - exp(s/a)*Ei(-s/a)/s)/s, 0, True)
    assert LT(log(t)/sqrt(t), t, s) ==\
        (sqrt(pi)*(-log(s) - 2*log(2) - S.EulerGamma)/sqrt(s), 0, True)
    assert LT(t**(S(5)/2)*log(t), t, s) ==\
        (15*sqrt(pi)*(-log(s)-2*log(2)-S.EulerGamma+S(46)/15)/(8*s**(S(7)/2)),
         0, True)
    assert (LT(t**3*log(t), t, s, noconds=True)-6*(-log(s) - S.EulerGamma\
                                    + S(11)/6)/s**4).simplify() == S.Zero
    assert LT(log(t)**2, t, s) ==\
        (((log(s) + EulerGamma)**2 + pi**2/6)/s, 0, True)
    assert LT(exp(-a*t)*log(t), t, s) ==\
        ((-log(a + s) - S.EulerGamma)/(a + s), -a, True)
    # Trigonometric functions (laplace6.pdf)
    assert LT(sin(a*t), t, s) == (a/(a**2 + s**2), 0, True)
    assert LT(Abs(sin(a*t)), t, s) ==\
        (a*coth(pi*s/(2*a))/(a**2 + s**2), 0, True)
    assert LT(sin(a*t)/t, t, s) == (atan(a/s), 0, True)
    assert LT(sin(a*t)**2/t, t, s) == (log(4*a**2/s**2 + 1)/4, 0, True)
    assert LT(sin(a*t)**2/t**2, t, s) ==\
        (a*atan(2*a/s) - s*log(4*a**2/s**2 + 1)/4, 0, True)
    assert LT(sin(2*sqrt(a*t)), t, s) ==\
        (sqrt(pi)*sqrt(a)*exp(-a/s)/s**(S(3)/2), 0, True)
    assert LT(sin(2*sqrt(a*t))/t, t, s) == (pi*erf(sqrt(a)*sqrt(1/s)), 0, True)
    assert LT(cos(a*t), t, s) == (s/(a**2 + s**2), 0, True)
    assert LT(cos(a*t)**2, t, s) ==\
        ((2*a**2 + s**2)/(s*(4*a**2 + s**2)), 0, True)
    assert LT(sqrt(t)*cos(2*sqrt(a*t)), t, s) ==\
        (sqrt(pi)*(-2*a + s)*exp(-a/s)/(2*s**(S(5)/2)), 0, True)
    assert LT(cos(2*sqrt(a*t))/sqrt(t), t, s) ==\
        (sqrt(pi)*sqrt(1/s)*exp(-a/s), 0, True)
    assert LT(sin(a*t)*sin(b*t), t, s) ==\
        (2*a*b*s/((s**2 + (a - b)**2)*(s**2 + (a + b)**2)), 0, True)
    assert LT(cos(a*t)*sin(b*t), t, s) ==\
        (b*(-a**2 + b**2 + s**2)/((s**2 + (a - b)**2)*(s**2 + (a + b)**2)),
         0, True)
    assert LT(cos(a*t)*cos(b*t), t, s) ==\
        (s*(a**2 + b**2 + s**2)/((s**2 + (a - b)**2)*(s**2 + (a + b)**2)),
         0, True)
    assert LT(c*exp(-b*t)*sin(a*t), t, s) == (a*c/(a**2 + (b + s)**2),
                                              -b, True)
    assert LT(c*exp(-b*t)*cos(a*t), t, s) == ((b + s)*c/(a**2 + (b + s)**2),
                                              -b, True)
    assert LT(cos(x + 3), x, s) == ((s*cos(3) - sin(3))/(s**2 + 1), 0, True)
    # Error functions (laplace7.pdf)
    assert LT(erf(a*t), t, s) == (exp(s**2/(4*a**2))*erfc(s/(2*a))/s, 0, True)
    assert LT(erf(sqrt(a*t)), t, s) == (sqrt(a)/(s*sqrt(a + s)), 0, True)
    assert LT(exp(a*t)*erf(sqrt(a*t)), t, s) ==\
        (sqrt(a)/(sqrt(s)*(-a + s)), a, True)
    assert LT(erf(sqrt(a/t)/2), t, s) == ((1-exp(-sqrt(a)*sqrt(s)))/s, 0, True)
    assert LT(erfc(sqrt(a*t)), t, s) ==\
        ((-sqrt(a) + sqrt(a + s))/(s*sqrt(a + s)), 0, True)
    assert LT(exp(a*t)*erfc(sqrt(a*t)), t, s) ==\
        (1/(sqrt(a)*sqrt(s) + s), 0, True)
    assert LT(erfc(sqrt(a/t)/2), t, s) == (exp(-sqrt(a)*sqrt(s))/s, 0, True)
    # Bessel functions (laplace8.pdf)
    assert LT(besselj(0, a*t), t, s) == (1/sqrt(a**2 + s**2), 0, True)
    assert LT(besselj(1, a*t), t, s) ==\
        (a/(sqrt(a**2 + s**2)*(s + sqrt(a**2 + s**2))), 0, True)
    assert LT(besselj(2, a*t), t, s) ==\
        (a**2/(sqrt(a**2 + s**2)*(s + sqrt(a**2 + s**2))**2), 0, True)
    assert LT(t*besselj(0, a*t), t, s) ==\
        (s/(a**2 + s**2)**(S(3)/2), 0, True)
    assert LT(t*besselj(1, a*t), t, s) ==\
        (a/(a**2 + s**2)**(S(3)/2), 0, True)
    assert LT(t**2*besselj(2, a*t), t, s) ==\
        (3*a**2/(a**2 + s**2)**(S(5)/2), 0, True)
    assert LT(besselj(0, 2*sqrt(a*t)), t, s) == (exp(-a/s)/s, 0, True)
    assert LT(t**(S(3)/2)*besselj(3, 2*sqrt(a*t)), t, s) ==\
        (a**(S(3)/2)*exp(-a/s)/s**4, 0, True)
    assert LT(besselj(0, a*sqrt(t**2+b*t)), t, s) ==\
        (exp(b*s - b*sqrt(a**2 + s**2))/sqrt(a**2 + s**2), 0, True)
    assert LT(besseli(0, a*t), t, s) == (1/sqrt(-a**2 + s**2), a, True)
    assert LT(besseli(1, a*t), t, s) ==\
        (a/(sqrt(-a**2 + s**2)*(s + sqrt(-a**2 + s**2))), a, True)
    assert LT(besseli(2, a*t), t, s) ==\
        (a**2/(sqrt(-a**2 + s**2)*(s + sqrt(-a**2 + s**2))**2), a, True)
    assert LT(t*besseli(0, a*t), t, s) == (s/(-a**2 + s**2)**(S(3)/2), a, True)
    assert LT(t*besseli(1, a*t), t, s) == (a/(-a**2 + s**2)**(S(3)/2), a, True)
    assert LT(t**2*besseli(2, a*t), t, s) ==\
        (3*a**2/(-a**2 + s**2)**(S(5)/2), a, True)
    assert LT(t**(S(3)/2)*besseli(3, 2*sqrt(a*t)), t, s) ==\
        (a**(S(3)/2)*exp(a/s)/s**4, 0, True)
    assert LT(bessely(0, a*t), t, s) ==\
        (-2*asinh(s/a)/(pi*sqrt(a**2 + s**2)), 0, True)
    assert LT(besselk(0, a*t), t, s) ==\
        (log(s + sqrt(-a**2 + s**2))/sqrt(-a**2 + s**2), a, True)
    assert LT(sin(a*t)**8, t, s) ==\
        (40320*a**8/(s*(147456*a**8 + 52480*a**6*s**2 + 4368*a**4*s**4 +\
                        120*a**2*s**6 + s**8)), 0, True)

    # Test general rules and unevaluated forms
    # These all also test whether issue #7219 is solved.
    assert LT(Heaviside(t-1)*cos(t-1), t, s) == (s*exp(-s)/(s**2 + 1), 0, True)
    assert LT(a*f(t), t, w) == a*LaplaceTransform(f(t), t, w)
    assert LT(a*Heaviside(t+1)*f(t+1), t, s) ==\
        a*LaplaceTransform(f(t + 1)*Heaviside(t + 1), t, s)
    assert LT(a*Heaviside(t-1)*f(t-1), t, s) ==\
        a*LaplaceTransform(f(t), t, s)*exp(-s)
    assert LT(b*f(t/a), t, s) == a*b*LaplaceTransform(f(t), t, a*s)
    assert LT(exp(-f(x)*t), t, s) == (1/(s + f(x)), -f(x), True)
    assert LT(exp(-a*t)*f(t), t, s) == LaplaceTransform(f(t), t, a + s)
    assert LT(exp(-a*t)*erfc(sqrt(b/t)/2), t, s) ==\
        (exp(-sqrt(b)*sqrt(a + s))/(a + s), -a, True)
    assert LT(sinh(a*t)*f(t), t, s) ==\
        LaplaceTransform(f(t), t, -a+s)/2 - LaplaceTransform(f(t), t, a+s)/2
    assert LT(sinh(a*t)*t, t, s) ==\
        (-1/(2*(a + s)**2) + 1/(2*(-a + s)**2), a, True)
    assert LT(cosh(a*t)*f(t), t, s) ==\
        LaplaceTransform(f(t), t, -a+s)/2 + LaplaceTransform(f(t), t, a+s)/2
    assert LT(cosh(a*t)*t, t, s) ==\
        (1/(2*(a + s)**2) + 1/(2*(-a + s)**2), a, True)
    assert LT(sin(a*t)*f(t), t, s) ==\
        I*(-LaplaceTransform(f(t), t, -I*a + s) +\
           LaplaceTransform(f(t), t, I*a + s))/2
    assert LT(sin(a*t)*t, t, s) ==\
        (2*a*s/(a**4 + 2*a**2*s**2 + s**4), 0, True)
    assert LT(cos(a*t)*f(t), t, s) ==\
        LaplaceTransform(f(t), t, -I*a + s)/2 +\
        LaplaceTransform(f(t), t, I*a + s)/2
    assert LT(cos(a*t)*t, t, s) ==\
        ((-a**2 + s**2)/(a**4 + 2*a**2*s**2 + s**4), 0, True)
    # The following two lines test whether issues #5813 and #7176 are solved.
    assert LT(diff(f(t), (t, 1)), t, s) == s*LaplaceTransform(f(t), t, s)\
        - f(0)
    assert LT(diff(f(t), (t, 3)), t, s) == s**3*LaplaceTransform(f(t), t, s)\
        - s**2*f(0) - s*Subs(Derivative(f(t), t), t, 0)\
            - Subs(Derivative(f(t), (t, 2)), t, 0)
    assert LT(a*f(b*t)+g(c*t), t, s) == a*LaplaceTransform(f(t), t, s/b)/b +\
        LaplaceTransform(g(t), t, s/c)/c
    assert inverse_laplace_transform(
        f(w), w, t, plane=0) == InverseLaplaceTransform(f(w), w, t, 0)
    assert LT(f(t)*g(t), t, s) == LaplaceTransform(f(t)*g(t), t, s)

    # additional basic tests from wikipedia
    assert LT((t - a)**b*exp(-c*(t - a))*Heaviside(t - a), t, s) == \
        ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True)
    assert LT((exp(2*t) - 1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \
        == exp(-b)/(s**2 - 1)

    # DiracDelta function: standard cases
    assert LT(DiracDelta(t), t, s) == (1, 0, True)
    assert LT(DiracDelta(a*t), t, s) == (1/a, 0, True)
    assert LT(DiracDelta(t/42), t, s) == (42, 0, True)
    assert LT(DiracDelta(t+42), t, s) == (0, 0, True)
    assert LT(DiracDelta(t)+DiracDelta(t-42), t, s) == \
        (1 + exp(-42*s), 0, True)
    assert LT(DiracDelta(t)-a*exp(-a*t), t, s) == (s/(a + s), 0, True)
    assert LT(exp(-t)*(DiracDelta(t)+DiracDelta(t-42)), t, s) == \
        (exp(-42*s - 42) + 1, -oo, True)

    # Collection of cases that cannot be fully evaluated and/or would catch
    # some common implementation errors
    assert LT(DiracDelta(t**2), t, s) == LaplaceTransform(DiracDelta(t**2), t, s)
    assert LT(DiracDelta(t**2 - 1), t, s) == (exp(-s)/2, -oo, True)
    assert LT(DiracDelta(t*(1 - t)), t, s) == \
        LaplaceTransform(DiracDelta(-t**2 + t), t, s)
    assert LT((DiracDelta(t) + 1)*(DiracDelta(t - 1) + 1), t, s) == \
        (LaplaceTransform(DiracDelta(t)*DiracDelta(t - 1), t, s) + \
         1 + exp(-s) + 1/s, 0, True)
    assert LT(DiracDelta(2*t-2*exp(a)), t, s) == (exp(-s*exp(a))/2, 0, True)
    assert LT(DiracDelta(-2*t+2*exp(a)), t, s) == (exp(-s*exp(a))/2, 0, True)

    # Heaviside tests
    assert LT(Heaviside(t), t, s) == (1/s, 0, True)
    assert LT(Heaviside(t - a), t, s) == (exp(-a*s)/s, 0, True)
    assert LT(Heaviside(t-1), t, s) == (exp(-s)/s, 0, True)
    assert LT(Heaviside(2*t-4), t, s) == (exp(-2*s)/s, 0, True)
    assert LT(Heaviside(-2*t+4), t, s) == ((1 - exp(-2*s))/s, 0, True)
    assert LT(Heaviside(2*t+4), t, s) == (1/s, 0, True)
    assert LT(Heaviside(-2*t+4), t, s) == ((1 - exp(-2*s))/s, 0, True)

    # Fresnel functions
    assert laplace_transform(fresnels(t), t, s) == \
        ((-sin(s**2/(2*pi))*fresnels(s/pi) + sin(s**2/(2*pi))/2 -
            cos(s**2/(2*pi))*fresnelc(s/pi) + cos(s**2/(2*pi))/2)/s, 0, True)
    assert laplace_transform(fresnelc(t), t, s) == (
        ((2*sin(s**2/(2*pi))*fresnelc(s/pi) - 2*cos(s**2/(2*pi))*fresnels(s/pi)
        + sqrt(2)*cos(s**2/(2*pi) + pi/4))/(2*s), 0, True))

    # Matrix tests
    Mt = Matrix([[exp(t), t*exp(-t)], [t*exp(-t), exp(t)]])
    Ms = Matrix([[    1/(s - 1), (s + 1)**(-2)],
                 [(s + 1)**(-2),     1/(s - 1)]])

    # The default behaviour for Laplace tranform of a Matrix returns a Matrix
    # of Tuples and is deprecated:
    with warns_deprecated_sympy():
        Ms_conds = Matrix([[(1/(s - 1), 1, True), ((s + 1)**(-2),
            -1, True)], [((s + 1)**(-2), -1, True), (1/(s - 1), 1, True)]])
    with warns_deprecated_sympy():
        assert LT(Mt, t, s) == Ms_conds
    # The new behavior is to return a tuple of a Matrix and the convergence
    # conditions for the matrix as a whole:
    assert LT(Mt, t, s, legacy_matrix=False) == (Ms, 1, True)
    # With noconds=True the transformed matrix is returned without conditions
    # either way:
    assert LT(Mt, t, s, noconds=True) == Ms
    assert LT(Mt, t, s, legacy_matrix=False, noconds=True) == Ms
예제 #20
0
def test_laplace_transform():
    from sympy import fresnels, fresnelc
    LT = laplace_transform
    a, b, c, = symbols('a b c', positive=True)
    t = symbols('t')
    w = Symbol("w")
    f = Function("f")

    # Test unevaluated form
    assert laplace_transform(f(t), t, w) == LaplaceTransform(f(t), t, w)
    assert inverse_laplace_transform(f(w), w, t,
                                     plane=0) == InverseLaplaceTransform(
                                         f(w), w, t, 0)

    # test a bug
    spos = symbols('s', positive=True)
    assert LT(exp(t), t, spos)[:2] == (1 / (spos - 1), True)

    # basic tests from wikipedia

    assert LT((t - a)**b*exp(-c*(t - a))*Heaviside(t - a), t, s) == \
        ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True)
    assert LT(t**a, t, s) == (s**(-a - 1) * gamma(a + 1), 0, True)
    assert LT(Heaviside(t), t, s) == (1 / s, 0, True)
    assert LT(Heaviside(t - a), t, s) == (exp(-a * s) / s, 0, True)
    assert LT(1 - exp(-a * t), t, s) == (a / (s * (a + s)), 0, True)

    assert LT((exp(2*t) - 1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \
        == exp(-b)/(s**2 - 1)

    assert LT(exp(t), t, s)[:2] == (1 / (s - 1), 1)
    assert LT(exp(2 * t), t, s)[:2] == (1 / (s - 2), 2)
    assert LT(exp(a * t), t, s)[:2] == (1 / (s - a), a)

    assert LT(log(t / a), t,
              s) == ((log(a * s) + EulerGamma) / s / -1, 0, True)

    assert LT(erf(t), t, s) == ((erfc(s / 2)) * exp(s**2 / 4) / s, 0, True)

    assert LT(sin(a * t), t, s) == (a / (a**2 + s**2), 0, True)
    assert LT(cos(a * t), t, s) == (s / (a**2 + s**2), 0, True)
    # TODO would be nice to have these come out better
    assert LT(exp(-a * t) * sin(b * t), t,
              s) == (b / (b**2 + (a + s)**2), -a, True)
    assert LT(exp(-a*t)*cos(b*t), t, s) == \
        ((a + s)/(b**2 + (a + s)**2), -a, True)

    assert LT(besselj(0, t), t, s) == (1 / sqrt(1 + s**2), 0, True)
    assert LT(besselj(1, t), t, s) == (1 - 1 / sqrt(1 + 1 / s**2), 0, True)
    # TODO general order works, but is a *mess*
    # TODO besseli also works, but is an even greater mess

    # test a bug in conditions processing
    # TODO the auxiliary condition should be recognised/simplified
    assert LT(exp(t) * cos(t), t, s)[:-1] in [
        ((s - 1) / (s**2 - 2 * s + 2), -oo),
        ((s - 1) / ((s - 1)**2 + 1), -oo),
    ]

    # Fresnel functions
    assert laplace_transform(fresnels(t), t, s) == \
        ((-sin(s**2/(2*pi))*fresnels(s/pi) + sin(s**2/(2*pi))/2 -
            cos(s**2/(2*pi))*fresnelc(s/pi) + cos(s**2/(2*pi))/2)/s, 0, True)
    assert laplace_transform(
        fresnelc(t), t,
        s) == (((2 * sin(s**2 / (2 * pi)) * fresnelc(s / pi) -
                 2 * cos(s**2 / (2 * pi)) * fresnels(s / pi) +
                 sqrt(2) * cos(s**2 / (2 * pi) + pi / 4)) / (2 * s), 0, True))

    assert LT(Matrix([[exp(t), t*exp(-t)], [t*exp(-t), exp(t)]]), t, s) ==\
        Matrix([
            [(1/(s - 1), 1, True), ((s + 1)**(-2), 0, True)],
            [((s + 1)**(-2), 0, True), (1/(s - 1), 1, True)]
        ])
예제 #21
0
from sympy import * 
from sympy.integrals.transforms import laplace_transform,inverse_laplace_transform
from sympy.simplify.fu import L
s,L=symbols('s,L')
t=symbols('t',positive=True)
y0=0
y10=0
Ly2=s**2*L-s*y0-y10
Ly1=s*L-y0
Ly=L
algeq=Eq(Ly2-Ly1,laplace_transform(exp(4*t),t,s,noconds=True))
print("18MEC24006-DENNY JOHNSON P")
print(algeq)
algsoln=solve(algeq,L)[0]
print(algsoln)
soln=inverse_laplace_transform(algsoln,s,t,noconds=True)
print("Solution:y(t)=",soln)
예제 #22
0
# coding: utf-8
# 참고문헌: http://docs.sympy.org/dev/modules/integrals/integrals.html#sympy.integrals.transforms.laplace_transform
#   http://www.mathalino.com/reviewer/advance-engineering-mathematics/table-laplace-transforms-elementary-functions

import sympy as sp
from sympy.integrals.transforms import inverse_laplace_transform
from sympy.integrals.transforms import laplace_transform

t, s = sp.symbols('t s')
w = sp.Symbol('w', real=True)
a = sp.Symbol('a', real=True)
p = sp.Symbol('p', real=True)

y = a * sp.sin(w * t + p)
print("y = %s" % y)

Y = laplace_transform(y, t, s)
print("Y = %s" % str(Y))

yi = inverse_laplace_transform(Y[0], s, t)
print("yi = %s" % str(yi))
예제 #23
0
from sympy import * 
from sympy.integrals.transforms import laplace_transform,inverse_laplace_transform
from sympy.simplify.fu import L
s,L=symbols('s,L')
t=symbols('t',positive=True)
y0=2
y10=1
Ly2=s**2*L-s*y0-y10
Ly1=s*L-y0
Ly=L
algeq=Eq(Ly2+Ly1-2*Ly,laplace_transform(4,t,s,noconds=True))
print("18MEC24006-DENNY JOHNSON P")
print(algeq)
algsoln=solve(algeq,L)[0]
print(algsoln)
soln=inverse_laplace_transform(algsoln,s,t,noconds=True)
print("Solution:y(t)=",soln)
예제 #24
0
def test_issue_14692():
    b = Symbol('b', negative=True)
    assert laplace_transform(1/(I*x - b), x, s) == \
        (-I*exp(I*b*s)*expint(1, b*s*exp_polar(I*pi/2)), 0, True)
예제 #25
0
def test_laplace_transform():
    from sympy import fresnels, fresnelc

    LT = laplace_transform
    a, b, c, = symbols("a b c", positive=True)
    t = symbols("t")
    w = Symbol("w")
    f = Function("f")

    # Test unevaluated form
    assert laplace_transform(f(t), t, w) == LaplaceTransform(f(t), t, w)
    assert inverse_laplace_transform(f(w), w, t, plane=0) == InverseLaplaceTransform(f(w), w, t, 0)

    # test a bug
    spos = symbols("s", positive=True)
    assert LT(exp(t), t, spos)[:2] == (1 / (spos - 1), True)

    # basic tests from wikipedia

    assert LT((t - a) ** b * exp(-c * (t - a)) * Heaviside(t - a), t, s) == (
        (s + c) ** (-b - 1) * exp(-a * s) * gamma(b + 1),
        -c,
        True,
    )
    assert LT(t ** a, t, s) == (s ** (-a - 1) * gamma(a + 1), 0, True)
    assert LT(Heaviside(t), t, s) == (1 / s, 0, True)
    assert LT(Heaviside(t - a), t, s) == (exp(-a * s) / s, 0, True)
    assert LT(1 - exp(-a * t), t, s) == (a / (s * (a + s)), 0, True)

    assert LT((exp(2 * t) - 1) * exp(-b - t) * Heaviside(t) / 2, t, s, noconds=True) == exp(-b) / (s ** 2 - 1)

    assert LT(exp(t), t, s)[:2] == (1 / (s - 1), 1)
    assert LT(exp(2 * t), t, s)[:2] == (1 / (s - 2), 2)
    assert LT(exp(a * t), t, s)[:2] == (1 / (s - a), a)

    assert LT(log(t / a), t, s) == ((log(a * s) + EulerGamma) / s / -1, 0, True)

    assert LT(erf(t), t, s) == ((erfc(s / 2)) * exp(s ** 2 / 4) / s, 0, True)

    assert LT(sin(a * t), t, s) == (a / (a ** 2 + s ** 2), 0, True)
    assert LT(cos(a * t), t, s) == (s / (a ** 2 + s ** 2), 0, True)
    # TODO would be nice to have these come out better
    assert LT(exp(-a * t) * sin(b * t), t, s) == (b / (b ** 2 + (a + s) ** 2), -a, True)
    assert LT(exp(-a * t) * cos(b * t), t, s) == ((a + s) / (b ** 2 + (a + s) ** 2), -a, True)

    assert LT(besselj(0, t), t, s) == (1 / sqrt(1 + s ** 2), 0, True)
    assert LT(besselj(1, t), t, s) == (1 - 1 / sqrt(1 + 1 / s ** 2), 0, True)
    # TODO general order works, but is a *mess*
    # TODO besseli also works, but is an even greater mess

    # test a bug in conditions processing
    # TODO the auxiliary condition should be recognised/simplified
    assert LT(exp(t) * cos(t), t, s)[:-1] in [
        ((s - 1) / (s ** 2 - 2 * s + 2), -oo),
        ((s - 1) / ((s - 1) ** 2 + 1), -oo),
    ]

    # Fresnel functions
    assert laplace_transform(fresnels(t), t, s) == (
        (
            -sin(s ** 2 / (2 * pi)) * fresnels(s / pi)
            + sin(s ** 2 / (2 * pi)) / 2
            - cos(s ** 2 / (2 * pi)) * fresnelc(s / pi)
            + cos(s ** 2 / (2 * pi)) / 2
        )
        / s,
        0,
        True,
    )
    assert laplace_transform(fresnelc(t), t, s) == (
        (
            sin(s ** 2 / (2 * pi)) * fresnelc(s / pi) / s
            - cos(s ** 2 / (2 * pi)) * fresnels(s / pi) / s
            + sqrt(2) * cos(s ** 2 / (2 * pi) + pi / 4) / (2 * s),
            0,
            True,
        )
    )

    assert LT(Matrix([[exp(t), t * exp(-t)], [t * exp(-t), exp(t)]]), t, s) == Matrix(
        [[(1 / (s - 1), 1, True), ((s + 1) ** (-2), 0, True)], [((s + 1) ** (-2), 0, True), (1 / (s - 1), 1, True)]]
    )
예제 #26
0
# 쥬피터에서 가능 파이참과 같은 프로그램에서는 다른 방법 사용
init_printing()
%matplotlib inline 

# 함수 f(t)의 라플라스 변환을 정의
# sympy의 라플라스 변환과 역변환 모듈을 도입, 변수  s  와 상수들을 선언
from sympy.integrals.transforms import laplace_transform
from sympy.integrals.transforms import inverse_laplace_transform

s = symbols('s')
a, ω = symbols('a ω', constant=True, positive=True)

# (라플라스 변환, 수렴조건들)
# 라플라스 변환만 출력하고 싶으면 noconds=True를 작성
# f(t) = 1
laplace_transform( 1, t, s )

# f(t) = t^2 * e^at
laplace_transform( (t**2)*exp(a*t), t, s, noconds=True )

# f(t) = e^at * sin(ωt)
laplace_transform(exp(a*t) * sin(ω*t), t, s, noconds=True )

# f(t) = e^-at * cos(ωt)
laplace_transform(exp(-a*t) * cos(ω*t), t, s, noconds=True )

# f(t) = t* e^-at
laplace_transform( (t)*exp(-a*t), t, s, noconds=True )

# f(t) = t^2
laplace_transform(t*t, t, s, noconds=True )
예제 #27
0
from sympy import *
from sympy.integrals.transforms import laplace_transform, inverse_laplace_transform
from sympy.simplify.fu import L
s, L = symbols('s,L')
t = symbols('t', positive=True)
y0 = 0
y10 = 0
Ly2 = s**2 * L - s * y0 - y10
Ly1 = s * L - y0
Ly = L
algeq = Eq(Ly2 - 4 * Ly, laplace_transform(cos(t), t, s, noconds=True))
print("18MEC24006-DENNY JOHNSON P")
print(algeq)
algsoln = solve(algeq, L)[0]
print(algsoln)
soln = inverse_laplace_transform(algsoln, s, t, noconds=True)
print("Solution:y(t)=", soln)
예제 #28
0
def test_laplace_transform():
    from sympy import fresnels, fresnelc, DiracDelta
    LT = laplace_transform
    a, b, c, = symbols('a b c', positive=True)
    t = symbols('t')
    w = Symbol("w")
    f = Function("f")

    # Test unevaluated form
    assert laplace_transform(f(t), t, w) == LaplaceTransform(f(t), t, w)
    assert inverse_laplace_transform(f(w), w, t,
                                     plane=0) == InverseLaplaceTransform(
                                         f(w), w, t, 0)

    # test a bug
    spos = symbols('s', positive=True)
    assert LT(exp(t), t, spos)[:2] == (1 / (spos - 1), 1)

    # basic tests from wikipedia
    assert LT((t - a)**b*exp(-c*(t - a))*Heaviside(t - a), t, s) == \
        ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True)
    assert LT(t**a, t, s) == (s**(-a - 1) * gamma(a + 1), 0, True)
    assert LT(Heaviside(t), t, s) == (1 / s, 0, True)
    assert LT(Heaviside(t - a), t, s) == (exp(-a * s) / s, 0, True)
    assert LT(1 - exp(-a * t), t, s) == (a / (s * (a + s)), 0, True)

    assert LT((exp(2*t) - 1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \
        == exp(-b)/(s**2 - 1)

    assert LT(exp(t), t, s)[:2] == (1 / (s - 1), 1)
    assert LT(exp(2 * t), t, s)[:2] == (1 / (s - 2), 2)
    assert LT(exp(a * t), t, s)[:2] == (1 / (s - a), a)

    assert LT(log(t / a), t,
              s) == ((log(a * s) + EulerGamma) / s / -1, 0, True)

    assert LT(erf(t), t, s) == (erfc(s / 2) * exp(s**2 / 4) / s, 0, True)

    assert LT(sin(a * t), t, s) == (a / (a**2 + s**2), 0, True)
    assert LT(cos(a * t), t, s) == (s / (a**2 + s**2), 0, True)
    # TODO would be nice to have these come out better
    assert LT(exp(-a * t) * sin(b * t), t,
              s) == (b / (b**2 + (a + s)**2), -a, True)
    assert LT(exp(-a*t)*cos(b*t), t, s) == \
        ((a + s)/(b**2 + (a + s)**2), -a, True)

    assert LT(besselj(0, t), t, s) == (1 / sqrt(1 + s**2), 0, True)
    assert LT(besselj(1, t), t, s) == (1 - 1 / sqrt(1 + 1 / s**2), 0, True)
    # TODO general order works, but is a *mess*
    # TODO besseli also works, but is an even greater mess

    # test a bug in conditions processing
    # TODO the auxiliary condition should be recognised/simplified
    assert LT(exp(t) * cos(t), t, s)[:-1] in [
        ((s - 1) / (s**2 - 2 * s + 2), -oo),
        ((s - 1) / ((s - 1)**2 + 1), -oo),
    ]

    # DiracDelta function: standard cases
    assert LT(DiracDelta(t), t, s) == (1, -oo, True)
    assert LT(DiracDelta(a * t), t, s) == (1 / a, -oo, True)
    assert LT(DiracDelta(t / 42), t, s) == (42, -oo, True)
    assert LT(DiracDelta(t + 42), t, s) == (0, -oo, True)
    assert LT(DiracDelta(t)+DiracDelta(t-42), t, s) == \
        (1 + exp(-42*s), -oo, True)
    assert LT(DiracDelta(t) - a * exp(-a * t), t,
              s) == (-a / (a + s) + 1, 0, True)
    assert LT(exp(-t)*(DiracDelta(t)+DiracDelta(t-42)), t, s) == \
        (exp(-42*s - 42) + 1, -oo, True)
    # Collection of cases that cannot be fully evaluated and/or would catch
    # some common implementation errors
    assert LT(DiracDelta(t**2), t,
              s) == LaplaceTransform(DiracDelta(t**2), t, s)
    assert LT(DiracDelta(t**2 - 1), t, s) == (exp(-s) / 2, -oo, True)
    assert LT(DiracDelta(t*(1 - t)), t, s) == \
        LaplaceTransform(DiracDelta(-t**2 + t), t, s)
    assert LT((DiracDelta(t) + 1)*(DiracDelta(t - 1) + 1), t, s) == \
        (LaplaceTransform(DiracDelta(t)*DiracDelta(t - 1), t, s) + \
         1 + exp(-s) + 1/s, 0, True)
    assert LT(DiracDelta(2*t - 2*exp(a)), t, s) == \
        (exp(-s*exp(a))/2, -oo, True)

    # Fresnel functions
    assert laplace_transform(fresnels(t), t, s) == \
        ((-sin(s**2/(2*pi))*fresnels(s/pi) + sin(s**2/(2*pi))/2 -
            cos(s**2/(2*pi))*fresnelc(s/pi) + cos(s**2/(2*pi))/2)/s, 0, True)
    assert laplace_transform(
        fresnelc(t), t,
        s) == (((2 * sin(s**2 / (2 * pi)) * fresnelc(s / pi) -
                 2 * cos(s**2 / (2 * pi)) * fresnels(s / pi) +
                 sqrt(2) * cos(s**2 / (2 * pi) + pi / 4)) / (2 * s), 0, True))

    # What is this testing:
    Ne(1 / s, 1) & (0 < cos(Abs(periodic_argument(s, oo))) * Abs(s) - 1)

    Mt = Matrix([[exp(t), t * exp(-t)], [t * exp(-t), exp(t)]])
    Ms = Matrix([[1 / (s - 1), (s + 1)**(-2)], [(s + 1)**(-2), 1 / (s - 1)]])

    # The default behaviour for Laplace tranform of a Matrix returns a Matrix
    # of Tuples and is deprecated:
    with warns_deprecated_sympy():
        Ms_conds = Matrix([[(1 / (s - 1), 1, s > 1), ((s + 1)**(-2), 0, True)],
                           [((s + 1)**(-2), 0, True),
                            (1 / (s - 1), 1, s > 1)]])
    with warns_deprecated_sympy():
        assert LT(Mt, t, s) == Ms_conds

    # The new behavior is to return a tuple of a Matrix and the convergence
    # conditions for the matrix as a whole:
    assert LT(Mt, t, s, legacy_matrix=False) == (Ms, 1, s > 1)

    # With noconds=True the transformed matrix is returned without conditions
    # either way:
    assert LT(Mt, t, s, noconds=True) == Ms
    assert LT(Mt, t, s, legacy_matrix=False, noconds=True) == Ms