ECE 280/Fall 2023/MAPLE

From PrattWiki
Revision as of 02:40, 2 October 2023 by DukeEgr93 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This web page is meant to support the Maple Intro for the Fall 2023 ECE 280 class.

Accessing Maple

See the Using Maple: Duke Container section of the Maple page for how to reserve a Maple container and then use it. Containers are accessed via web browsers so you will not need any additional software to use Maple in this way.

Maple Basics

Go through the Other Pundit Pages on the Maple page, specifically:

Then go through the Connected Curriculum Project - Engineering Maple Tutor modules 1-11. Note that modules 12 and 14 may not come up much in this course but are interesting nonetheless! A few notes:

  • You do not need semicolons anymore...unless you are trying to have one line do multiple things, then those things need to be divided by semicolons
  • A colon at the end of a thing tells Maple to do that thing but suppress viewing the results
  • Part 4: F5 is no longer the shortcut to enter text; easiest way is to go to Insert>Paragraph>Before or After Cursor, depending on what you want to do
  • Part 7: Maple now re-writes a line such as g(x):=10*sin(x) to be g(x):=x->10*sin(x)

Examples From Chapter 1

The following will take you through steps to find answers to several different kinds of problem in the class. The parts in this section come from examples in Chapter 1 of "Signals and Systems: Theory and Applications" by Fawwaz Ulaby and Andrew Yagle and available for free at [ss2.eecs.umich.edu]

Initializing Worksheets

Your worksheets should always start with the following:

restart

so that if you re-run the whole worksheet, Maple will start from scratch.

Later in this example, you will be using the display command which comes from a module named plots. As a result, just after the restart command, you should have:

with(plots):

Singularity Functions

  • Maple has a version of the continuous step function already available - it is called Heaviside and is defined as 0 when the argument is <0, 1 when the argument is >0, and undefined when the argument is 0. Maple can handle most graphics and math even with this undefined instant. If you need to explicitly define the value of the Heaviside function at 0, you can do that with:
    • NumericEventHandler(invalid_operation=`Heaviside/EventHandler`(value_at_zero=1)):
  • Because you will probable not want to type out that entire word, you may want to start your Maple script with some basic definitions of singularity functions. Note the semi-colons are in the lines below so you ca n copy and paste the section into a single command line in Maple.
u:=t->Heaviside(t);
r:=t->t*u(t);
q:=t->t^2/2*u(t);
c:=t->t^3/6*u(t);

Defining and Plotting Functions

One of the example functions in the Ulaby book is in Figure 1-8; we will be using this to show some signal transformations. The signal is made up of a ramp function of amplitude 5 that is on for 2 seconds. One way to define this is:

x := t -> 5*r(t)-5*r(t-2)-10*u(t-2)

If you want to make a quick plot of it, you can use:

plot(x(t), t=-1..5)

If you want to make something that more closely resembles Figure 1-8, you can do that by putting multiple functions in the plot command:

plot([x(2*t), x(t), x(t/2)], t=-1..5)

Another example function is used on Figures 1-7 and 1-9. That one is a little more complicated, but can be written (approximately) as:

x2 := t -> 2.8*sqrt(t)*u(t) + ((-1)*2.8*sqrt(t) + 5.6*exp(-1/3*t + 4/3))*u(t - 4)

If you want to get something that resembles Figure 1-7, you can do that with:

plot([x2(t + 10), x2(t), x2(t - 10)], t = -11 .. 30, legend = ["x(t+10)", "x(t)", "x(t-10)"])

Note the addition of a legend.

To get Figure 1-9, you can use:

plot([x2(-t), x2(t)], t = -20 .. 20, color = ["green", "red"], legend = ["x(-t)", "x(t)"])

Note the addition of color information; up until now, Maple's default color choices have matched the book. This time, however, they did not.

Figure 1-10 has a new function $$x(t)=r(t+3)-r(t+2)-u(t)+e^{-t}u(t)$$ We can get that with:

x3 := t -> r(t + 3) - r(t + 2) - u(t) + exp(-t)*u(t)

and then create an array of stacked plots with:

A := Array(1 .. 3, 1 .. 1);
A[1, 1] := plot(x(t), t = -5 .. 6, title = "x(t)");
A[2, 1] := plot(x(-2*t), t = -5 .. 6, title = "z(t)=x(-2t)");
A[3, 1] := plot(x(-2*(t - 3)), t = -5 .. 6, title = "y(t)");
display(A, size = [300, 200]);

For Figure 1-11, first note that the equations in the book are only valid if $$x(t)=0$$ for $$t<=$$; if that is not the case, you ned to use $$x_e(t)=\frac{x(t)+x(-t)}{2}$$ and $$x_o(t)=\frac{x(t)-x(-t)}{2}$$. Then you would want to write something like:

B := Array(1 .. 3, 1 .. 1);
B[1, 1] := plot(x2(t), t = -12 .. 12, title = "x(t)");
B[2, 1] := plot((x2(t) + x2(-t))/2, t = -12 .. 12, title = "Even Part");
B[3, 1] := plot((x2(t) - x2(-t))/2, t = -12 .. 12, title = "Odd Part");
display(B, size = [300, 200]);

To create and plot a periodic function, you basically need to define one period as a function and then define another function that passes an argument based on the remainder of time with the period of the function. Note that Maple's mod command is meant for polynomials and not floating point evaluation. I recommend creating a new command called nmod() to figure out the remainder part and then use it with periodic functions:

nmod := (t, T) -> t/T - floor(t/T);
x4a := t -> 5*r(t) - 5*r(t - 2) - 10*u(t - 2)
x4b := t -> x4a(nmod(t, 2))
plot(x4b(t), t = -5 .. 7)

Examples From Chapter 2

The parts in this section come from examples in Chapter 2 of "Signals and Systems: Theory and Applications" by Fawwaz Ulaby and Andrew Yagle and available for free at [ss2.eecs.umich.edu]

Initializing Worksheets / Defining Singularity Functions

Once again, your worksheet should start with the following to restart everything, load the plots module, and define singularity functions:

restart;
with(plots):
NumericEventHandler(invalid_operation=`Heaviside/EventHandler`(value_at_zero=1)):
u:=t->Heaviside(t);
r:=t->t*u(t);
q:=t->t^2/2*u(t);
c:=t->t^3/6*u(t);


Defining Convolution

  • If you have two functions defined, you can perform convolution in Maple by using the convolution integral; for example, if you want to convolve $$x(t)=u(t)-u(t-3)$$ and $$h(t)=e^{-t}u(t)$$, you can write:
    x := t -> u(t) - u(t - 3);
    h := t -> exp(-t)*u(t);
    int(x(tau)*h(t - tau), tau = -infinity .. infinity);
  • If you want to plot that, you could change the last time above to a function and then plot $$x(t)$$ and $$y(t)$$ on the same graph:
    y := t -> int(x(tau)*h(t - tau), tau = -infinity .. infinity);
    plot([x(t), y(t)], t = -1 .. 8, color=["blue", "red"], size=[300, 300],legend = ["x(t)", "y(t)"]);
    where the colors are set simply to match Ulaby's color scheme while also having $$x(t)$$ show up first in the legend...
  • You can also create a function that will perform convolution by receiving two functions as arguments, changing the independent variable on those functions, and performing convolutions. That is to say:
    convolve := (a, b) -> int(subs(t = tau, a)*subs(t = t - tau, b), tau = -infinity .. infinity);
    y := t -> convolve(x(t), h(t));
    y(t);
  • Typically you will get a piecewise result; if you want to see a version built with Heaviside functions you can use:
    convert(y(t), Heaviside)
    whereas if you get a version with Heaviside functions and you want to see the piecewise version you can use:
    convert(y(t), piecewise)

Convolving and Plotting

  • The next example in the demo is from Figure 2-9 with $$x_1(t)=r(t)-2r(t-1)+r(t)$$ and $$h_1(t)=e^{-t}u(t)$$
  • The example after that is from Figure 2-11 with $$x_2(t)=u(t)-u(t-1)$$ and $$h_2(t)=2e^{-2t}u(t)$$
  • The last example is from Figure 2-23 with $$x_3(t)=r(t)-2r(t-1)+r(t-2)$$ and $$h_3(t)=u(t)-2u(t-1)+u(t-2)$$