Maple/Spring 2024 Startup

From PrattWiki
Revision as of 15:49, 2 April 2024 by DukeEgr93 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This document is meant to take you step-by-step through using Maple to solve problems involving Laplace Transforms and Inverse Laplace Transforms.

Using Maple

Adding the inttrans functions

Maple does not automatically know how to do Laplace or inverse Laplace transforms - those commands are in a module called inttrans and the way you will load that module into Maple is with the command with(inttrans). If you do not need to see the results of loading the module, you can put a : at the end of the line, which tells Maple to suppress the output (i.e. with(inttrans):).

Helping Maple understand step functions

Generally, Maple leaves Heaviside(0) as undefined; that can get unwieldy later, so teaching Maple to assign that a value can be helpful. We will go ahead and teach Malpe that Heaviside(0)=1, which is consistent with discrete time step functions. The command to do that is:

with(inttrans)

Useful Maple commands for work with Laplace Transforms

The page at Maple/Laplace Transforms goes into detail about some help functions, and then summarizes them at Maple/Laplace_Transforms#Typical_Starting_Commands_When_Working_With_Laplace.

Defining functions

The easiest way to define a function in Maple is:

FUN_NAME := function

If you want to explicitly note what a function is a function of, or you want to be able to call it with explicit arguments later, you can use:

FUN_NAME := (IN1, IN2, ...) -> function

For Lab 10, you will not need to use the latter form except in the useful Maple commands already given above.

Making numerical substitutions

Before taking Laplace or inverse Laplace transforms, you may need to replace symbols with numbers. The easiest way to do this is with the subs command. The subs command will be a sequence of equalities for the substitutions followed by the item into which substitutions are made. The substitutions are only made in the last item! Here are two examples - one with all the substitutions done in a single command, and one where a list of equations is defined and then used:

Hn := subs(R = 10000., C = 0.000100, SCS(H, s))

or

MyVals := R = 10000., C = 0.000100
Hn := subs(MyVals, SCS(H, s))

Note that in each the "SCS" or "Simplify / Collect / Sort" command is used to make the transfer function look better.

Taking Laplace transforms

Easy as:

laplace(function, t, s)

Taking Inverse Laplace transforms

Easy as:

invlaplace(function, s, t)

though there are two helper versions of the inverse to look at. The function IL is defined to do partial fraction expansion before taking the inverse, which sometimes results in a cleaner answer. This command only works if the transform is a ratio of polynomials of s and does not include exponentials in s (either because of time shifts or being right-sided periodic). Given that, for transforms that are ratios of polynomials, you can use

IL(function, s, t)

and for transforms that involve time shifts, you can use

ILTS(function, s, t)

Plotting results

If you have a variable that is an implied function of $$t$$, you can make a plot by giving the plot command the function and a range for t. Here are examples of plotting a single item and plotting two items:

  • Single item with axis labels and title:
plot(h*u(t), t = -1 .. 5, labeldirections = [horizontal, vertical], labels = ["Time (s)", "Voltage (V)"], title = "Impulse Response")
  • Two items with legend, axis labels, title, and specific colors:
plot([u(t), sr*u(t)], t = -1 .. 5, legend = ["input", "output"], labeldirections = [horizontal, vertical], labels = ["Time (s)", "Voltage (V)"], color = [black, red], title = "Step Response")

Submitting your Files

The easiest way to submit your files (PDF or MW) will be to use the Firefox browser in the container, log in to Gradescope, and upload things there.