To run Mathematica, proceed as directed on the previous
tutorial.
*Do not forget to set the DISPLAY
variable as directed there!* The main new commands we will be
using here are
called

In[1] := << Calculus`LaplaceTransform`To save space, I will avoid including the output which Mathematica returns ; I advise you to read what it returns to make sure there are no mistakes.

We can use Mathematica to evaluate this integral
for many relevant choices of **f**. The command is
defined with the following syntax:
**LaplaceTransform[f[t],t,s]**.

LaplaceTransform[Sin[a t],t,s] LaplaceTransform[t^2,t,s] LaplaceTransform[t^3,t,s] LaplaceTransform[a t^2 + b t^3,t,s]Easy enough.

The purpose of introducing you to this example is primarily to illustrate some new ways of thinking when using Mathematica and to teach you some new commands. Let's get started:

Suppose the function **f(t)** is periodic of period **P**.
By this, I mean that the **f(t)=f(t+P)**, for all real numbers **t**.
Then it can be shown that the Laplace Transform is equal
to

Now, let us use Mathematica to find the
Laplace Transform of
**f(t)**, which we define to be
**f(t)=1-t** if **0 <= t <= 1** and **f(t)=f(t-1)** if
**t>1**.
First we define the function and plot it
for our own good.

In[3] := Clear[f] In[4] := f[x_] := 1-x /; 0 <= x <=1 In[5] := f[x_] := f[x-1] /; x > 1 In[6] := Plot[f[x],{x,0,5},PlotRange->{0,3/2},Ticks->{Automatic,{0,.5,1,1.5}}]NOTE that before beginning Mathematica you should have set the

Now, using the above equation with **P=1** and **f(t)=1-t**,
we can arrive at the Laplace Transform through the
following sequence of commands:

In[7] := stepone = Integrate[(1-t)Exp[-s t],{t,0,1}] In[8] := lf = 1/(1-Exp[-s]) stepone//SimplifyIn line 7, we evaluated the integral using Mathematica and called the answer

In[10] := InverseLaplaceTransform[1/(8+4s+s^2),s,t]To avoid having to retype

In[11] := ILT = InverseLaplaceTransformwithin Mathematica. Now, we can proceed as before but without having to do as much typing. Nice!

In[12] := ILT[1/(8+4s+s^2),s,t]Note: You do not have to use ILT as your alias. Feel free to use whatever you want ; I will continue to use ILT throughout the remainder of this handout.

ILT[1/s^2,s,t] ILT[s/(s^2+4),s,t] ILT[a s/(s^2+4) - b/(s^2-4),s,t]

**
1/(s^n (s*s+16))**, for **n=0,1,2,3,4,5,6.
**

A good exercise for you is to show that if **F(n)** denotes
the inverse Laplace transform for **1/(s^n(s*s+16))**,
then one can compute the **F(n+1)** by the following
formula:

Thus we can set up a recursion relation in Mathematica as follows:

In[13] := Clear[F] In[14] := F[0] = ILT[1/(s^2+16),s,t] In[15] := F[n_] := F[n] = Integrate[F[n-1] /. t->a, {a,0,t}]We end this exercise by printing out the results in table form:

In[16] := Table[{n,F[n]},{n,0,6}]//TableFormNotice again here that we used the double-slash notation to take the output of the first command and use it as input to the second command,

For the first problem, let's solve
**y''+2y'+4y=t-exp(-t)**, subject to **y(0)=1**
and **y'(0)=-1**.

In[17] := lhsone=LaplaceTransform[y''[t]+2y'[t]+4y[t],t,s]After taking the Laplace Transform of the differential equation, we can plug in the initial values and make a substitution for the Transform of

In[18] := lhstwo = lhsone /. {LaplaceTransform[y[t],t,s]->capy,y[0]->1,y'[0]->-1}Now we compute the transform of the right hand side:

In[19] := rhs=LaplaceTransform[t-Exp[-t],t,s]and solve for

In[20] := stepthree=Solve[lhstwo==rhs,capy]Now we must extract the solution from all of the surrounding brakets with the following command:

In[21] := stepfour=stepthree[[1,1,2]]so we can then compute the inverse transform and find the solution to our problem!

In[22] := sol=ILT[stepfour,s,t]

The above six steps can be used as a general recipe for solving differential equations using the Laplace Transform, provided Mathematica knows the transform of the left annd right hand side. In some cases, you may have to do some of the work on your own, "by hand", before proceeding.

We can define a function like this in Mathematica with the command

f[x_] := If[x<=5,0,1] Plot[f[x],{x,0,7}]However, if we try to use Mathematica to compute the Laplace Transform of this function, we see that it fails to do anything useful:

In[33]:= LaplaceTransform[f[t],t,s] Out[33]= LaplaceTransform[If[t <= 5, 0, 1], t, s]Thus, in order to solve the differential equation from above with this right hand side, we will have to either appeal to the tables from our textbook to compute the Laplace Transform for this function on our own, or we have Mathematica to the integral for us as follows:

In[34]:= rhs = Integrate[ Exp[-s t],{t,5,Infinity}] 1 Out[34]= ------ 5 s E sHad we put in the expression

Assuming you have not cleared the variables that were defined above, we can now solve the problem with the following commands:

In[35]:= stepthree=Solve[lhstwo==rhs,capy]; In[36]:= stepfour=stepthree[[1,1,2]]; In[37]:= sol=ILT[stepfour,s,t] 5 - t Cos[Sqrt[3] t] 1 E Cos[Sqrt[3] (-5 + t)] Out[37]= -------------- + (- - ---------------------------- - t 4 4 E 5 - t E Sin[Sqrt[3] (-5 + t)] > ----------------------------) UnitStep[-5 + t] 4 Sqrt[3] In[38]:= Plot[sol,{t,-1,15}]

lhsone=LaplaceTransform[y''[t]+2y'[t]+4y[t],t,s] lhstwo = lhsone /. {LaplaceTransform[y[t],t,s]->capy,y[0]->1,y'[0]->-1} rhs=LaplaceTransform[UnitStep[t-5],t,s] stepthree=Solve[lhstwo==rhs,capy] stepfour=stepthree[[1,1,2]] sol=ILT[stepfour,s,t] Plot[sol,{t,-1,15}]and there you have it. With this information, you should be able to easily solve a lot of homework-type problems just by using Mathematica!

Please feel free to send me email if you have any questions.