Difference between revisions of "Maple/Laplace Transforms"
Line 132: | Line 132: | ||
for those with time shifts. In both cases, the conversion to expsincos eliminates any complex exponentials (when possible). | for those with time shifts. In both cases, the conversion to expsincos eliminates any complex exponentials (when possible). | ||
− | + | == Typical Starting Commands When Working With Laplace == | |
+ | The following is a good set of commands with which to begin any worksheet where Laplace is used: | ||
+ | <source lang="text"> | ||
+ | restart; | ||
+ | with(inttrans); | ||
+ | PAR := (Ra , Rb) -> simplify(Ra*Rb/( Ra+Rb)); | ||
+ | SCS := X -> sort(collect(simplify(X), s), s); | ||
+ | IL := (X, s, t) -> simplify(convert(invlaplace( convert(X,parfrac),s, t), expsincos)); | ||
+ | ILTS := (X, s, t) -> simplify(convert(invlaplace(X, s, t),expsincos)); | ||
+ | </source> | ||
== Questions == | == Questions == |
Revision as of 16:36, 19 January 2011
Maple does not know how to do Laplace transforms out of the box,
but like so many entities, it can be taught. The inttrans
package for Maple contains algorithms for performing many useful
functions, including forward and inverse Laplace transforms. To load
it, simply type
with(inttrans)
into your worksheet. The list of new commands will show up. If you want to load the commands without seeing them, simply put a colon at the end of the
with(inttrans):
line. This is generally true for
Maple - the colon at the end will suppress display of the result.
Note also that Maple does understand the unit step function natively - it
calls it Heaviside(t)
.
Contents
Basic Laplace and Inverse Laplace Transforms
The forward and inverse Laplace transform commands are simply laplace
and
invlaplace
. They take three arguments - the item
to be transformed, the original variable, and the transformed
variable. For Laplace transforms, the second and third arguments
will typically be t and s, respectively. Conversely, for invlaplace
,
the second and third arguments will be s and t, respectively.
For example, to get the Laplace Transform of what Dr. G refers to as the Mother Of All Transforms, that is,
\( \mathcal{L}\left\{ e^{-at}\left(A\cos(\omega t)+B\sin(\omega t)\right) \right\} \)
you could add:
MOAT:=exp(-a*t)*(A*cos(omega*t)+B*sin(omega*t));
MOATLAP:=laplace(MOAT, t, s)
which returns:
\( {\it MOATLAP} := {\frac {As+Aa+B\omega}{ \left( s+a \right) ^{2}+{\omega}^{2}}} \)
To find the inverse Laplace of:
\( \mathcal{H}(s)=\frac{e^{-s}}{\left(s+a\right)^2}-\frac{s}{s+a} \)
you could type:
H:=exp(-s)/(s+a)^2-s/(s+a);
h:=invlaplace(H, s, t)
again being careful to note when Maple automatically adds subscripts, superscripts, and fractional parts for you. Maple returns:
\( h:={\it Heaviside} \left( t-1 \right) \left( t-1 \right) {e^{-a \left( t -1 \right) }}-{\it Dirac} \left( t \right) +a{e^{-at}} \)
which has two new functions in it - Heaviside and Dirac. Heaviside is Maple's unit step function and Direc is Maple's Dirac delta function - i.e. the impulse. The expression above, then, could also be written as:
\( h:=(t-1)e^{-a(t-1)}u(t-1)-\delta(t)+ae^{-at}u(t)\,\! \)
where the final u(t) is implied due to Maple's using the unilateral Laplace transform. Notice the time shift in the first term of the result - this is a function of the exponential in the Laplace version.
It is critical to note that Maple performs the unilateral Laplace transform. To prove this, note that the following three lines:
X1 := laplace(Heaviside(t-2), t, s);
X2 := laplace(Heaviside(t), t, s);
X3 := laplace(Heaviside(t+2), t, s);
will yield
\( \begin{align} {\it X1}&:={\frac {{e^{-2\,s}}}{s}}\\ {\it X2}&:={\frac {1}{s}}\\ {\it X3}&:={\frac {1}{s}} \end{align} \)
and notice that the results of the latter two commands are the same. The step function u(t+2) is one starting at time t=-2, but the unilateral Laplace transform only looks at the signal starting at time 0, so it might as well be u(t).
For more proof - and more insight to the unilateral Laplace transform - note that the following code:
x1:=invlaplace(laplace(Heaviside(t-2), t, s), s, tau);
x2:=invlaplace(laplace(Heaviside(t), t, s), s, tau);
x3:=invlaplace(laplace(Heaviside(t+2), t, s), s, tau)
yields:
\( \begin{align} {\it x1}&:={\it Heaviside} \left( \tau-2 \right)\\ {\it x2}&:=1\\ {\it x3}&:=1 \end{align} \)
where \(\tau\) here is being used to clearly indicate the different between the original time variable and the time variable used by the inverse transform.
Better Inverse Laplace Transforms
For inverse Laplace transforms, a little bit of processing can go a long way. Specifically, consider the following:
with(inttrans) x := exp(-t)+cos(80*t) X1 := laplace(x, t, s) X2 := simplify(X1)
At this point, X1 and X2 represent the laplace transform of the same function; they are just presented differently since X2 is the simplified version of X1. However, when taking the inverse:
x1 := invlaplace(X1, s, t) x2 := invlaplace(X2, s, t)
a disaster happens - x1 returns the original x while x2 returns...a mess. One way around this is to have Maple split the Laplace transform into partial fractions, then take the inverse of those parts; writing
x2a := invlaplace(convert(X2, parfrac), s, t)
will yield the original x. One caveat - this only works if the Laplace transform is a ratio of polynomials; if there are any time shifts, represented by exponentials of s in the transform, the conversion to a partial fraction will fail. For this reason, you may want to construct two different versions of the inverse Laplace transform simplifier:
IL := (X, s, t) -> simplify(convert(invlaplace(convert(X, parfrac), s, t), expsincos))
for taking the inverse of Laplace transforms that are ratios of polynomials and
ILTS := (X, s, t) -> simplify(convert(invlaplace(X, s, t), expsincos))
for those with time shifts. In both cases, the conversion to expsincos eliminates any complex exponentials (when possible).
Typical Starting Commands When Working With Laplace
The following is a good set of commands with which to begin any worksheet where Laplace is used:
restart;
with(inttrans);
PAR := (Ra , Rb) -> simplify(Ra*Rb/( Ra+Rb));
SCS := X -> sort(collect(simplify(X), s), s);
IL := (X, s, t) -> simplify(convert(invlaplace( convert(X,parfrac),s, t), expsincos));
ILTS := (X, s, t) -> simplify(convert(invlaplace(X, s, t),expsincos));
Questions
Post your questions by editing the discussion page of this article. Edit the page, then scroll to the bottom and add a question by putting in the characters *{{Q}}, followed by your question and finally your signature (with four tildes, i.e. ~~~~). Using the {{Q}} will automatically put the page in the category of pages with questions - other editors hoping to help out can then go to that category page to see where the questions are. See the page for Template:Q for details and examples.