\documentclass[12pt]{article}

\usepackage{amsmath,amssymb,amsthm}

\usepackage{color}

%\usepackage[textheight=8.5in, margin=1.6in]{geometry}
\usepackage[total={6in,8in}]{geometry}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
%\tikzstyle{ball} = [circle,shading=ball, ball color=black,
%    minimum size=1mm,inner sep=1.3pt]
%\usetikzlibrary{arrows.meta}
%\tikzset{>={Latex[length=2mm,width=1.5mm]}}

%\usepackage{graphicx}

\usepackage[shortlabels]{enumitem}
\setlist[enumerate]{leftmargin=*,label=(\alph*)}

\usepackage{needspace}  % <-- to prevent bad pagebreak over environment titles
% Use:  \Needspace{3\baselineskip} before opening an environment

\usepackage[colorlinks=true,citecolor=black,linkcolor=black,urlcolor=blue]{hyperref}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\sn}{\mathfrak{S}}
\newcommand{\ve}{\varepsilon}
\newcommand{\ips}[2]{\langle{#1}, {#2}\rangle}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Span}{\mathrm{Span}}
\DeclareMathOperator{\rk}{\mathrm{rank}}
\DeclareMathOperator{\trace}{\mathrm{tr}}
\DeclareMathOperator{\im}{\mathrm{im}}
\DeclareMathOperator{\Sym}{\mathrm{Sym}}
\DeclareMathOperator{\Hom}{\mathrm{Hom}}
\DeclareMathOperator{\diag}{\mathrm{diag}}
\DeclareMathOperator{\glb}{\mathrm{glb}}
\DeclareMathOperator{\lub}{\mathrm{lub}}

\parskip = 0.05in
\parindent = 0.0in

%\pagestyle{empty}

\begin{document}
\centerline{Math 322 lecture for Wednesday, Week 5}
\bigskip

\centerline{\sc nonhomogeneous systems}
\medskip

\textbf{Proposition.}
Let~$A\in M_n(F)$ and consider the system
\[
  x'(t)=Ax(t) +b(t)
\]
where~$t\mapsto b(t)\in F^n$ is continuous.  The solution with initial
condition~$x_0$ is
\[
  x(t)=e^{At}x_0+e^{At}\int_{s=0}^te^{-As}b(s)\,ds.
\]
The solution is unique.
\begin{proof}
 Given in the last lecture: just take the derivative of the above
 expression.  Uniqueness is a homework problem.
\end{proof}

{\bf Note.} Our text has references for a system as in the Proposition but for
which~$A=A(t)$, i.e.,~$A$ varies with~$t$, too.
\medskip

{\bf Example.} Here is an example from our text for an equation modeling a
forced harmonic oscillator:
\[
  x''=-x+f(t).
\]
Writing~$x_1=x$ and~$x_2=x_1'$, we have
\[
  x_2'=x_1''=-x+f(t) = -x_1+f(t).
\]
Hence, we consider the system
\begin{align*}
  x_1'&= x_2\\
  x_2'&= -x_1+f(t)
\end{align*}
or let
\[
y := 
\left(\begin{array}{c}
    x_1\\x_2
\end{array} \right)
=
\left(\begin{array}{c}
    x\\
    x'
\end{array} \right)
\]
and consider the system
\[
  y'=\left(\begin{array}{rr}
      0&1\\
      -1&0
  \end{array} \right)
  y
  +
  \left(\begin{array}{c}
      0\\f(t)
  \end{array} \right).
\]
So we apply the proposition with
\[
A = 
  \left(\begin{array}{rr}
      0&1\\
      -1&0
  \end{array} \right)
  \quad\text{and}\quad
  b(t) =
  \left(\begin{array}{c}
      0\\f(t)
  \end{array} \right).
\]
Thus,
\[
  e^{At}=
  \left(\begin{array}{rr}
      \cos(t)&\sin(t)\\
      -\sin(t)&\cos(t)
  \end{array} \right),
\]
and
\begin{align*}
  y(t)
  &= e^{At}y_0+e^{At}\int_{s=0}^te^{-As}b(s)\,ds\\[10pt]
  &= \left(\begin{array}{rr}
      \cos(t)&\sin(t)\\
      -\sin(t)&\cos(t)
  \end{array} \right)y_0
  \\[10pt]
  &\qquad+\left(\begin{array}{rr}
      \cos(t)&\sin(t)\\
      -\sin(t)&\cos(t)
  \end{array} \right)\int_{s=0}^t\left(\begin{array}{rr}
      \cos(s)&-\sin(s)\\
      \sin(s)&\cos(s)
  \end{array} \right)\left(\begin{array}{c}
      0\\f(s)
  \end{array} \right)\,ds\\[10pt]
  &= \left(\begin{array}{rr}
      \cos(t)&\sin(t)\\
      -\sin(t)&\cos(t)
  \end{array} \right)y_0+\left(\begin{array}{rr}
      \cos(t)&\sin(t)\\
      -\sin(t)&\cos(t)
  \end{array} \right)\int_{s=0}^t\left(\begin{array}{c}
      -f(s)\sin(s)\\
      f(s)\cos(s)
  \end{array} \right)\,ds.
\end{align*}
The initial condition is~$y_0=(x_1(0),x_2(0))=(x(0),x'(0))$.  We take the
first component of the above~$2\times 1$ matrix to get the solution:
\begin{align*}
  x(t)
  &= 
  x(0)\cos(t)+x'(0)\sin(t)\\[5pt]
  &\quad+\cos(t)\left( -\int_{s=0}^tf(s)\sin(s)\,ds
  \right)+\sin(t)\left( \int_{s=0}^tf(s)\cos(s)\,ds \right)\\[5pt]
  &= 
  x(0)\cos(t)+x'(0)\sin(t)+\int_{s=0}^tf(s)\left(-\cos(t)\sin(s)+\sin(t)\cos(s)\right)\,ds.
\end{align*}
Now use the sum formula
\[
  \sin(\theta+\psi)=\cos(\theta)\sin(\psi)+\cos(\psi)\sin(\theta)
\]
with~$\theta=t$ and~$\psi=-s$ to get
\[
  x(t)= x(0)\cos(t)+x'(0)\sin(t)+\int_{s=0}^tf(s)\sin(t-s)\,ds.
\]
For a special case, suppose that~$f(s)=\cos(\omega t)$.  The solution is then
\[
  x(t)= x(0)\cos(t)+x'(0)\sin(t)+\int_{s=0}^t\cos(\omega s)\sin(t-s)\,ds.
\]
To integrate this, note that
\begin{align*}
  \sin(\theta+\psi)+\sin(\theta-\psi)
  &= \cos(\theta)\sin(\psi)+\cos(\psi)\sin(\theta)\\
  &\qquad -\cos(\theta)\sin(\psi)+\cos(\psi)\sin(\theta)\\
  &= 2\cos(\psi)\sin(\theta).
\end{align*}
Therefore,
\[
  \cos(\psi)\sin(\theta)=\frac{1}{2}\left( \sin(\theta+\psi)+\sin(\theta-\psi)
  \right).
\]
It follows that
\begin{align*}
  \int_{s=0}^t\cos(\omega s)\sin(t-s)\,ds
  &=
  \frac{1}{2}\int_{s=0}^t\sin(t+(\omega-1)s)+\sin(t-(\omega+1)s)\,ds\\[5pt]
  &=
  \left.\frac{1}{2}\left(-\frac{\cos(t+(\omega-1)s)}{\omega-1}+\frac{\cos(t-(\omega+1)s)}{\omega+1}\right)\right|_{s=0}^t\\[5pt]
    &= 	\frac{\cos(\omega t)-\cos(t)}{1-\omega^2}.
\end{align*}
So the solution is
\[
  x(t)= x(0)\cos(t)+x'(0)\sin(t)+\frac{\cos(\omega t)-\cos(t)}{1-\omega^2}.
\]
\begin{center}
  \begin{tikzpicture}
  \begin{axis}[ 
      title style={at={(0.5,0)},anchor=north,yshift=-30},
      title={Unforced: $x(0)=x'(0)=1$, $f(t)=0$},
      axis lines = middle,
      axis line style={->},
      %axis equal image,
      %ticks=none,
      xmin=-50,
      xmax=50,
      ymin=-2.3,
      ymax=2.3
    ]
    %\fill[blue] (axis cs: 1,1) circle (2pt);  
    %\fill[draw=black,fill=white] (axis cs:1,0) circle (2pt);  
    \addplot[domain=-50:50,thick,samples=500, blue]
    {cos(deg(x))+sin(deg(x))};
  \end{axis}
  \end{tikzpicture}
\end{center}
\begin{center}
  \begin{tikzpicture}
  \begin{axis}[ 
      title style={at={(0.5,0)},anchor=north,yshift=-30},
      title={$x(0)=x'(0)=1$, $\omega=0.1$},
      axis lines = middle,
      axis line style={->},
      %axis equal image,
      %ticks=none,
      xmin=-50,
      xmax=50,
      ymin=-2.3,
      ymax=2.3
    ]
    %\fill[blue] (axis cs: 1,1) circle (2pt);  
    %\fill[draw=black,fill=white] (axis cs:1,0) circle (2pt);  
    \addplot[domain=-50:50,thick,samples=500, blue]
    {cos(deg(x))+sin(deg(x))+(cos(deg(0.1*x))-cos(deg(x)))/(1-0.1*0.1)};
  \end{axis}
  \end{tikzpicture}
\end{center}

\begin{center}
  \begin{tikzpicture}
  \begin{axis}[ 
      title style={at={(0.5,0)},anchor=north,yshift=-30},
      title={$x(0)=x'(0)=1$, $f(t)=te^{-0.01t}$},
      axis lines = middle,
      axis line style={->},
      %axis equal image,
      %ticks=none,
      %xmin=-50,
      %xmax=50,
      %ymin=-2.3,
      %ymax=2.3
    ]
    %\fill[blue] (axis cs: 1,1) circle (2pt);  
    %\fill[draw=black,fill=white] (axis cs:1,0) circle (2pt);  
    \addplot[domain=1:1000,thick,samples=1000, blue]
    { 10000/100020001*(10001*x + 200)*e^(-1/100*x) + 98020001/100020001*cos(deg(x)) + 30001/100020001*sin(deg(x)) 
};
  \end{axis}
  \end{tikzpicture}
\end{center}
\end{document}
