% Laplace applications, 2280mapleL3-laplace-S2018.tex
\documentclass{article}
 \setlength{\oddsidemargin}{0in}
 \setlength{\evensidemargin}{0in}
 \setlength{\textwidth}{6.4in}
 \setlength{\textheight}{9.8in}
 \setlength{\parskip}{5pt}
 \setlength{\topmargin}{0pt} \setlength{\parindent}{0pt}
\input{linalg.sty}
\def\MAPLE{{\tt Maple}}
\def\floor{\mathop{\bf floor}\nolimits}
\def\twave{\mathop{\bf twave}\nolimits}
\def\sqwave{\mathop{\bf sqwave}\nolimits}
\def\rf#1{(\ref{#1})}
\def\Prob#1#2{\par\bigskip\par\noindent
{\Large\sf Problem #1}. {\bf #2}\par}
\parskip=3pt
\def\MAPLE{{\tt maple}}
\def\BF#1{{\bf #1}}
% \begin{topics}{template} ... \end{topics}
% used like enumerate, itemize, description environments
% The item[] is never optional!
%
%\newcommand{\topicslabel}[1]{\mbox{#1}\hfil}
%\newenvironment{topics}[1]{
%    \begin{list}{}{%
%      \let\makelabel\topicslabel
%      \settowidth{\labelwidth}{\topicslabel{#1}}
%      \setlength{\leftmargin}{\labelwidth}
%      \advance\leftmargin by 1.5em}
%}{\end{list}}
\pagestyle{plain}
\begin{document}
{\bf
Name~}\underline{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}\hfill
 {Class Time~}\underline{~~~~~~~~}

\begin{center}
\bf Math 2280
\bf Maple Project 3: Laplace Applications \\
\bf S2018
\end{center}


Maple lab 3 has five problems L3-1, L3-2, L3-3, L3-4, L3-5.

{\bf References}: %Edwards-Penney, pages 55--57.
Code in \MAPLE{} appears in \verb|2280mapleL3-laplace-S2018.txt| at URL
\verb|http://www.math.utah.edu/~gustafso/|. This document:
\verb|2280mapleL3-laplace-S2018.pdf|. Other related and required documents
are available at the web site.

%\begin{itemize}\sf
%
%\end{itemize}

\Prob{L3-1}{(Periodic Wave Plots)} In the table are examples of
standard periodic waves used in engineering applications. The last table
column has piecewise expressions $h$ defined on the base interval
$[0,T]$. 

Given an expression $h$ on the base $[0,T]$, then its $T$-periodic
extension $H$ to $(-\infty,\infty)$ is 
always $H(x)=h(g(x))$ where $g(x)=x-T \floor(x/T)$. 

In terms of the {\em triangular wave}  $\twave(x)=x-\floor(x)$, we
may write $g(x)= T \twave(x/T)$. The triangular wave is remembered as a
{\bf $T$-periodic train of ramps}. The {\em staircase function} $\floor(x)$
used in the construction of the ramp train is {\bf not periodic}; it is a
standard math library function in major programming languages.

\begin{itemize}
\item[{\bf (a)}]
 Plot all the periodic examples {\tt f1 to f7}. Please choose an appropriate
graph window for each.


\item[{\bf (b)}]
Justify every maple expression in the table. Use the example below as a
guide.
\end{itemize}

{\bf Example}. To justify the first table entry, which contains math
definition {\tt f1(x)} and piecewise definition {\tt h1(x)} for the
square wave, define {\tt H1(x)} to be the $T$-periodic extension of {\tt
h1(x)} to the whole real line, then plot {\tt H1(x)-f1(x)} over three
periods. The plot should be the zero function, i.e., the $x$-axis.
\begin{small}
\begin{verbatim}
 # Maple details for the example
 opt1:=ytickmarks=3,color=red,labels=[x,'f(x)'],title="square wave";
 opt2:=numpoints=100,thickness=2,discont=true;
 opts:=opt1,opt2;
 f1:=x -> (-1)^(floor(x)); 
 T:=2; # T = period = 2
 g:=x -> x-T*floor(x/T);
 h1:=x -> piecewise(x<1,1,x<2,-1,0);
 H1:=x -> h1(g(x)); # T-periodic extension
 plot(H1(x)-f1(x),x=0..3*T,opts); # Should plot as y=0 (the x-axis)
\end{verbatim}
\end{small}
\begin{center}\begin{tabular}{llll}
Maple Expression & Name & T & Piecewise Definition on $[0,T]$ \\ \hline
 \verb|f1:=x ->(-1)^floor(x);| & square wave & $2$ &
 $\dd h_1(x)=\left\{\begin{array}{rl} 1 & 0\le x < 1, \\ -1 & 1 \le x < 2\end{array}\right.$
\\[3ex]
 % opts:=thickness=2,numpoints=100,ytickmarks=3,discont=true:
 % f1 := x -> (-1)^floor(x);plot(f1(x),x=0..8.5,-1.2..1.2,title="square wave",opts);
 {\tt f2:=x -> x-floor(x);} & triangular wave & $1$ &
 $\dd h_2(x)= \left\{\begin{array}{cl} x & 0\le x < 1, \\ 0  & x=1\end{array}\right.$
 % f2 := x -> x-floor(x);plot(f2(x),x=0..5.5,-0.2..1.2,title="triangular wave",opts);
\\[3ex]
 \verb|f3:=x -> 1/2+(f2(x)-1/2)*f1(x);|& sawtooth wave & $2$ &
 $\dd h_3(x)=\left\{\begin{array}{cl} x & 0\le x < 1, \\ 2-x & 1 \le x < 2\end{array}\right.$
 % f3 := x -> 1/2+(f2(x)-1/2)*f1(x);plot(f3(x),x=0..6.5,-0.2..1.2,title="sawtooth wave",opts);
\\[3ex]
 {\tt f4:=x->abs(sin(x));} & rectified sine & $2\pi$ &
 $\dd h_4(x)=\left\{\begin{array}{rl} \sin(x) & 0\le x < \pi, \\ -\sin(x) & \pi \le x < 2\pi\end{array}\right.$
 % plot(abs(sin(x)),x=0..13.5,-0.2..1.2,title="rectified sine",opts);
\\[3ex]
 {\tt f5:=x->(sin(x)+abs(sin(x)))/2;} & half-wave rectified sine & $2\pi$ &
 $\dd h_5(x)=\left\{\begin{array}{cl} \sin(x) & 0\le x < \pi, \\ 0 & \pi \le x < 2\pi\end{array}\right.$
 % plot((sin(x)+abs(sin(x)))/2,x=0..16.5,-0.2..1.2,title="half-wave rectified sine",opts);
\\[3ex]
  \begin{minipage}{2.1in}{\tt p:= x -> (2-x)*x:\\
  f6:=t->p(2*f2(x/2))*f1(x/2);}\end{minipage}& parabolic wave & $4$ &
  $\dd h_6(x)=\left\{\begin{array}{cl} p(x) & 0\le x < 2, \\ -p(x-2) & 2 \le x <  4\end{array}\right.$
 % p:= x -> (2-x)*x:f6:=x->p(2*f2(x/2));plot(f6(x),x=0..16,-1.2..1.2,title="parabolic wave",opts);
\\[3ex]
% f periodic of period 2Pi, g=f on [0,2Pi]
 \begin{minipage}{2.5in}{\tt
 q:=x->\\
  piecewise(x<Pi,sin(x),x<2*Pi,-1):\\
  f7:=x->q(2*Pi*f2(x/2/Pi));}\end{minipage}& piecewise sine pulse & $2\pi$ &
 $\dd h_7(x)=\left\{\begin{array}{ll} \sin(x) & 0\le x < \pi, \\ -1 & \pi \le x < 2\pi\end{array}\right.$
 % plot(f(x),x=0..13.5,-1.2..1.2,title="piecewise sine pulse",opts);
\end{tabular}\end{center}
%# f periodic of period 3, g=f on [0,3]
%g := x -> piecewise(x<1,1,x<2,2,6-2*x):
%f := x -> g(x-3*floor(x/3)):
%plot(f(x),x=0..9.5,0..2.2,thickness=2,
%       color=COLOR(RGB,.9,.7,0),labels=[x,`f(x)`],ytickmarks=3);
%
%# f periodic of period 3, g=f on [0,3]
%g := x -> piecewise(x<1,x,x<2,1,3-x):
%f := x -> g(x-3*floor(x/3)):
%plot(f(x),x=0..9.5,0..1.2);
%
%# f periodic of period 2, g=f on [0,2]
%g := x -> piecewise(x<1,1-x,0):
%f := x -> g(x-2*floor(x/2)):
%plot(f(x),x=0..7.5,0..1.2);
%
%# f periodic of period 2, g=f on [0,2]
%g := x -> piecewise(x<1,x,1):
%f := x -> g(x-2*floor(x/2)):
%plot(f(x),x=0..7.5,0..1.2);
%
%# f periodic of period 2, g=f on [0,2]
%plot((1+(-1)^floor(x))/2,x=0..7.5,-0.2..1.2);


\Prob{L3-2}{(Hammer Hit Oscillation)} An attached mass in an
undamped spring-mass system is released from rest $1$ meter below
the equilibrium position. After $3$ seconds of oscillation, the mass
is struck by a hammer with force of $5$ Newtons in a downward
direction.

{\bf (a)} Assume the model
$$
\frac{d^2 x}{dt^2}+9x = 5\delta(t-3) ; x (0) = 1, \frac{dx}{dt} (0)
= 0,
$$
where $x(t)$ denotes the displacement from equilibrium at time t and
$\delta(t-3)$ denotes the Dirac delta function. Determine, using the
{\tt dsolve} example below, a piecewise-defined formula for $x(t)$.
Plot $x(t)$ for $0\le t \le 7$.

{\bf (b)} Solve the following hammer-hit models {\tt DE1} to {\tt DE4},
given as maple expressions, using the {\tt dsolve} example for {\tt
DE}, {\tt IC} as a template for the solution.

{\bf (c)} Express the symbolic answer for each of {\tt DE1} to {\tt DE4}
as a piecewise-defined function. Interpret each answer physically from
the initial conditions and the applied impulse.
\begin{verbatim}
 DE:=diff(x(t),t,t)+9*x(t)=3*Dirac(t-3); IC:=x(0)=1,D(x)(0)=0;
 dsolve({DE,IC},x(t),method=laplace);
 # x(t) = cos(3*t)+Heaviside(t-3)*sin(-9+3*t)
 convert(%,piecewise);combine(%,trig);
 # x(t) = cos(3*t) for t < 3,cos(3*t)+sin(-9+3*t) for t>3, undef t=3.

 DE1:=diff(x(t),t,t)+9*x(t)=5*Dirac(t-3); IC1:=x(0)=-1,D(x)(0)=1;
 DE2:=diff(x(t),t,t)+9*x(t)=6*Dirac(t-3); IC2:=x(0)=1,D(x)(0)=-1;
 DE3:=diff(x(t),t,t)+9*x(t)=8*Dirac(t-3); IC3:=x(0)=0,D(x)(0)=-1;
 DE4:=diff(x(t),t,t)+9*x(t)=9*Dirac(t-3); IC4:=x(0)=1,D(x)(0)=0;
\end{verbatim}

%  (a) Use Maple to find the Laplace transform of $f(t) = t e^{\alpha
%  t}$, where $\alpha$ is a constant.
%
%  (b) Use Maple to determine the function whose Laplace transform is
%  $a/(s^2*(s^2+a^2))$.


\Prob{L3-3}{(Maple Solution of Initial Value Problems)}

 {\bf (a)} Solve the IVP $y '' - y ' - 2 y = 5 \sin x$, $y (0) = 1$, $y'(0)=
 -1$. Please use the {\tt inttrans} package. Show the steps in Laplace's
 method, entirely in maple, with explicit use of maple functions
 {\tt laplace(f,t,s)} and {\tt invlaplace(F,s,t)}. The solution should
 duplicate the major steps that would be done by hand, table details omitted.

 {\bf (b)} Solve the pulse-input IVP
 $$3 y '' + 3 y ' + 2 y =
 \left\{\begin{array}{ll}
 0 & \mbox{for}\quad t < 0, \\
 3 & \mbox{for}\quad 0 \le t < 4, \\
 0 & \mbox{for}\quad  t \ge 4,
 \end{array}\right.
 $$
with initial data $y (0) = 0$, $y '(0) = 0$. Use any maple method.
Express your answer as a piecewise-defined function.

{\bf (c)} Solve the IVP $y '' + y = 1 + \delta(t-2\pi)$, $y (0) = 1$,
$y'(0) = 0$. Use maple {\tt dsolve}. Express the answer as a
piecewise-defined function.


\Prob{L3-4}{(Expressions for Periodic Waves)}

Let $h$ be the $T$-periodic extension to $-\infty < x < \infty$ of
$f(x)$, which is only defined on $0\le x \le T$.
Define $T=2$ and $f(x)=2/10+(7/10)\sin x +
(1/10)\cos 5x$ on $[0,T]$.

{\bf (a)} Plot $h(t)$ on the interval $[-10,10]$. Use the composition
formula $h(t)=f(g(t))$, where $g(t)=t-T\floor(t/T)$.

%f := x -> 2/10+7/10*sin(x)+1/10*cos(5*x):
%T:=2:                 # T==period
%g:=x->x-T*floor(x/T); # g==triangular wave of period T
%f_ := x -> f(g(x)):   # f_ == Extension of f as a periodic function
%plot(f(x),x=0..T);    # Periodic function f on base interval [0,T]
%plot(f_(x),x=-10..10,discont=true);

{\bf (b)} Compute the Laplace of $h(t)$ directly from the periodic
function theorem, using the sample maple code
\begin{center}\tt
int(f(g(t))*exp(-s*t),t=0..T)/(1-exp(-s*T));
\end{center}
Replacing $f(x)$ by $(1/10)\cos(5x)$ should give the answer below.
The answer for $2/10+(7/10)\sin x + (1/10)\cos 5x$ has many more
terms.
%\begin{center}
% \verb|1/10*(-s+exp(-2*s)*s*cos(10)-5*exp(-2*s)*sin(10))/((s^2+25)*(1-exp(-2*s)))|
%\end{center}
$$\frac{1}{10}\,{\frac {s{e^{2\,s}}-s\cos \left( 10 \right) +5\,\sin \left( 10
 \right) }{ \left( {s}^{2}+25 \right)  \left( -1+{e^{2\,s}} \right)
 }}$$

{\bf (c)} Maple directly finds the laplace of $g(t)=t-T\floor(t/T)$, but not
the laplace of $h(t)=f(g(t))$. Truncating
$f(x)=\frac{2}{10}+\frac{7}{10}\sin(x) +\frac{1}{10}\cos(5x)$ to the
constant term $2/10$ allows maple to compute the Laplace of $f(g(t))$.
But the sine and cosine terms do not evaluate.

To get help from maple, the function $h(t)$ is expressed as a series of
pulses. The laplace of the series $h(t)$ can be computed, provided
$\frac{1}{10}\cos(5x)$ is removed from $f(x)$. This example shows that
the periodic function theorem is a basic tool in Laplace theory. Here's
the success story for this example:
\begin{quote}\tt
  pulse:=(t,a,b)->Heaviside(t-a)-Heaviside(t-b);\\
  f := x -> 2/10+7/10*sin(x):
  h:= t->sum(f(t-n*T)*pulse(t,n*T,n*T+T),n=0..infinity); \\
  inttrans[laplace](h(t),t,s);\\
  eval(\%) assuming n::positive;
\end{quote}
Type this code into maple and report the answer. Check the answer by
comparing terms in the solution to part (b) above.


%with(inttrans):
%h1:=t->2/10+7/10*sin(g(t)); g:=x->x-2*floor(x/2);
%                      h1 := t -> 1/5 + 7/10 sin(g(t))
%
%                       g := x -> x - 2 floor(1/2 x)
%laplace(h1(t),t,s);
%               1
%              --- + 7/10 laplace(sin(t - 2 floor(t/2)), t, s)
%              5 s

\bigskip

{\bf REMARK}. Here's what does not work. Beware of testing the code
below: it uses about 800mb memory and may finish with no answer. If you
find a way to resolve the difficulty for all versions of maple, then
please send email, detailing how to do it.

\bigskip

\begin{quote}\tt
  pulse:=(t,a,b)->Heaviside(t-a)-Heaviside(t-b);\\
  f := x -> (1/10)*cos(5*x):\\
  h:= t->sum(f(t-n*T)*pulse(t,n*T,n*T+T),n=0..infinity); \\
  inttrans[laplace](h(t),t,s);\\
  eval(\%) assuming n::positive;
\end{quote}
%pulse:=(t,a,b)->Heaviside(t-a)-Heaviside(t-b);
%  f := x -> (1/10)*cos(5*x):F:=(x,n)->(1/10)*(cos(5*t)*cos(10*n)+sin(5*t)*sin(10*n));
%  h:= t->sum(F(t,n)*(pulse(t,n*T,n*T+T)),n=0..infinity);
%  h(1.0);
%laplace(F(t,n)*(pulse(t,n*T,n*T+T)),t,s)assuming n::positive;
%sum(%,n=0..infinity);

%
% f1:=t->2/10;f1_:= f1;laplace(f1_(t),t,s);
% f2:=t->7/10*sin(t);
% f2_:= t->sum(f2(t-n*T)*pulse(t,n*T,n*T+T),n=0..infinity);
% laplace(f2_(t),t,s);
% f3:=t->1/10*cos(5*t);
% f3_:= t->sum(f3(t-n*T)*pulse(t,n*T,n*T+T),n=0..infinity);
% laplace(f3_(t),t,s);
% int(f3(t)*exp(-s*t),t=0..T)/(1-exp(-s*T));
%
%
%#=====
%Resolvent method for systems of DE
%Solving integro-differntial systems

\bigskip

\Prob{L3-5}{(Resolvent Method)} The Laplace resolvent formula for
the problem $\.u'=A\.u$, $\.u(0)=\.u_0$ is
$$\L(\.u(t))=(sI-A)^{-1}\.u_0.$$
For example, $A=\twobytwo{1 & 0}{0 & 2}$ gives
$$\L(\.u(t)))=\twobytwo{s-1 & 0}{0 &
s-2}^{-1}\.u_0=\twobytwo{\frac{1}{s-1} & 0 }{0 &
\frac{1}{s-2}}\.u_0=\twobytwo{\L(e^t) & 0 }{0 & \L(e^{2t})}\.u_0,$$
which implies $\.u(t)=\twobytwo{e^t & 0 }{0 & e^{2t}}\.u_0$.

The answers for the components of $\.u$ are $\alpha e^t$, $\beta
e^{2t}$, according to the following maple code:
\begin{verbatim}
 with(LinearAlgebra):with(inttrans):
 A:=Matrix([[1,0],[0,2]]);
 u0:=Vector([alpha,beta]);
 B:=(s*IdentityMatrix(2)-A)^(-1).u0;
 u:=Map(invlaplace,B,s,t);
\end{verbatim}


\smallskip
Compute the solution $\.u(t)$ using the resolvent formula for the
following
cases.
\begin{itemize}
\item[\BF{(a)}] $A=\twobytwo{2 & 1}{1 & 2}$, $\.u(0)=\colvector{0\\ -1}$
\item[\BF{(b)}] $A=\twobytwo{0 & 1}{-1 & -2}$, $\.u(0)=\colvector{1\\ -1}$
\item[\BF{(c)}] $A=\twobytwo{2 & -5}{4 & -2}$, $\.u(0)=\colvector{-1\\ 2}$
\end{itemize}




\end{document}

\endinput

http://www.math.rpi.edu/MS_resources/maple.html

Good collection of beginner tutorials from various places.
