Functioneattnaf(t)+bg(t)f′(t)Laplace Transform1/(s−a)n!/sn+1aF(s)+bG(s)sF(s)−f(0)
Example. Solve u′(t)=−3u(t)+6t with initial condition u(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)