This page will walk you through computing Laplace transforms, inverse Laplace transforms, and using Laplace transforms to solve ODEs.
You can compute Laplace transforms. <sagecell> var('s,t') f=sin(3*t)
f.laplace(t,s)
</sagecell>
You can also compute inverse Laplace transforms.
<sagecell> var('s,t') F=(2*s+3)/(s^2+49)
F.inverse_laplace(s,t)
</sagecell>
You can compute the Laplace transform of an expression that involves derivatives of a function.
<sagecell> var('s,t') y=function('y', t)
expr = y.diff(t,2)+3*y.diff(t)+2
expr.laplace(t,s)
</sagecell>
You can compute the Laplace transform of both sides of an equation.
<sagecell> var('s,t') y=function('y', t)
eqn=y.diff(t)==2*t
eqn.laplace(t,s)
</sagecell>
After doing this, you can solve for the transformed function.
<sagecell> var('s,t') y=function('y', t)
eqn=y.diff(t)==2*t #Write the ODE subsidiary_equation = eqn.laplace(t,s) #Compute the Laplace transform of both sides
solve(subsidiary_equation, laplace(y, t, s)) #Solve for Y(s)
</sagecell>
After you solve for $Y$, just inverse Laplace transform both sides to get the solution to your differential equation.
<sagecell> var('s,t') y=function('y', t)
eqn=y.diff(t)==2*t #Write the ODE subsidiary_equation = eqn.laplace(t,s) #Compute the Laplace transform of both sides sol=solve(subsidiary_equation, laplace(y, t, s)) #Solve for Y(s)
Y=sol[0] #Solve returns an array. This gets the first entry in the array. Y.inverse_laplace(s,t) #Compute inverse transform </sagecell>
If you have initial conditions, remember to include them.
<sagecell> var('s,t') y=function('y', t)
eqn=y.diff(t)==2*t #Write the ODE y0=7 #State the initial condition. subsidiary_equation = eqn.laplace(t,s).subs(y(t=0)==y0) #Compute the Laplace transform of both sides
#The subs command says to replace y(0) with y0
sol=solve(subsidiary_equation, laplace(y, t, s)) #Solve for Y(s)
Y=sol[0] #Solve returns an array. This gets the first entry in the array. Y.inverse_laplace(s,t) #Compute inverse transform </sagecell>
If the ODE is higher order, you'll need more initial conditions.
<sagecell> var('s,t') y=function('y', t)
eqn=y.diff(t,2)+3*y.diff(t)+2*y==2*t #Write the ODE y0=7 #Multiple initial conditions. yp0=10 subsidiary_equation = eqn.laplace(t,s).subs(y(t=0)==y0).subs(y.diff(t)(t=0)==yp0) #Compute the Laplace transform of both sides sol=solve(subsidiary_equation, laplace(y, t, s)) #Solve for Y(s)
Y=sol[0] #Solve returns an array. This gets the first entry in the array. Y.inverse_laplace(s,t) #Compute inverse transform </sagecell>