Kernel: SageMath 9.7

C20 Laplace Transforms Part 1

FunctionLaplace Transformeat1/(sa)tnn!/sn+1af(t)+bg(t)aF(s)+bG(s)f(t)sF(s)f(0)\qquad \def\arraystretch{1.2} \begin{array}{ll} \text{Function} & \text{Laplace Transform}\\ \hline e^{at} & 1/(s-a) \\ t^n & n!/s^{n+1} \\ af(t) + bg(t) & aF(s) + bG(s) \\ f'(t) & sF(s) - f(0) \\ \end{array}

Example. Solve u(t)=3u(t)+6tu'(t) = -3u(t) + 6t with initial condition u(0)=1u(0) = 1.

# Define the differential equation var('s t'); u = function('u')(t) de = diff(u, t) == -3*u + 6*t; show(de)
# Use the Laplace transform le = laplace(de, t, s); show(le)
# Unfortunately, solving the above equation for `laplac(de, t, s)` does not work. # Instead we must first replace all function notation with symbolic variables. # This will be done by working with a string representation. # At the same time, we can resplace `u(0)` with 1. # Step 1 is to convert the symbolic equation into a string. le1 = str(le); le1
# Step 2 is to make the function-to-variable replacements in the string. le2 = le1.replace("laplace(u(t), t, s)", 'U').replace('u(0)', '1'); le2
# Step 3 is to converst the string back into a symbolic expression. var('U') le3 = sage_eval(le2, locals = {"s":s, "U":U}); le3
# Solve the Laplace equation. lsol = solve(le3, U); lsol
# As usual, Sage returns the result as a list. # We can extract the desired symbolic expression. lsoln = lsol[0].rhs(); show(lsoln)
# Partial fraction decomposition can be applied. lsoln.partial_fraction().show()
# Find the inverse of the Laplace transform. dsol(t) = inverse_laplace(lsoln, s, t); show(dsol)
# A graph can be obtained. plot(dsol, (0, 3), figsize = 4)