# University of Florida/Egm4313/s12.team11.imponenti/R6.4
## R6.4

solved by Luca Imponenti

#### Problem Statement

Consider the L2-ODE-CC (5) p.7b-7 with the window function f(x) p.9-8 as excitation:
       $y''-3y'+2y=f(x)\!$
and the initial conditions
       $y(0)=1\ ,\ y'(0)=0\!$
1. Find $y_{n}(x)\!$ such that:
    $y_{n}''+ay_{n}'+by_{n}=r_{n}(x)\!$
with the same initial conditions as above.
Plot $y_{n}(x)\!$ for $n=2,4,8\!$ for x in $[0,10]\!$
2. Use the matlab command ode45 to integrate the L2-ODE-CC, and plot the numerical solution to compare with the analytical solution.
    Level 1: $n=0,1\!$

#### Fourier Series

One period of the window function p9.8 is described as follows
    $f(x)={\begin{cases}0&\ \ -1.75<x<l0.25\\A&\ \ 0.25<x<2.25\\\end{cases}}$
From the above intervals one can see that the period, $p=4\!$ and therefore $L=2\!$ Applying the Euler formulas from $-1.75$ to $2.25\!$ the Fourier coefficients are computed:
$a_{0}={\frac {1}{2L}}\int _{-1.75}^{2.25}f(x)\ dx\!$
$a_{0}={\frac {1}{4}}(\int _{-1.75}^{0.25}0\ dx+\int _{0.25}^{2.25}A\ dx)\!$
$a_{0}=+{\frac {1}{4}}(0+\int _{0.25}^{2.25}A\ dx)\!$
$a_{0}={\frac {1}{4}}(2.25A-0.25A)\!$
$a_{0}={\frac {A}{2}}\!$
The integral from $-1.75\!$ to $0.25\!$ can be omitted from this point on since it is always zero.
$a_{n}={\frac {1}{L}}\int _{0.25}^{2.25}f(x)cos({\frac {n\pi x}{L}})\ dx\!$
$a_{n}={\frac {1}{2}}\int _{0.25}^{2.25}Acos({\frac {n\pi x}{2}})\ dx\!$
$a_{n}={\frac {2A}{2n\pi }}(sin({\frac {2.25n\pi }{2}})-sin({\frac {0.25n\pi }{2}})\!$
$a_{n}={\frac {A}{n\pi }}(sin({\frac {9n\pi }{8}})-sin({\frac {n\pi }{8}})\!$
and
$b_{n}={\frac {1}{L}}\int _{0.25}^{2.25}f(x)sin({\frac {n\pi x}{L}})\ dx\!$
$b_{n}={\frac {1}{2}}\int _{0.25}^{2.25}Asin({\frac {n\pi x}{2}})\ dx\!$
$b_{n}={\frac {2A}{2n\pi }}(cos({\frac {2.25n\pi }{2}})-cos({\frac {0.25n\pi }{2}})\!$
$b_{n}={\frac {A}{n\pi }}(Acos({\frac {n\pi }{8}})-Acos({\frac {9n\pi }{8}})\!$
The coefficients give the Fourier series:
$f(x)=a_{0}+\sum _{n=1}^{\infty }[a_{n}cos({\frac {n\pi x}{L}})+b_{n}sin({\frac {n\pi x}{L}})]\!$
$f(x)={\frac {A}{2}}+\sum _{n=1}^{\infty }[{\frac {A}{n\pi }}(sin({\frac {9n\pi }{8}})-sin({\frac {n\pi }{8}}))cos({\frac {n\pi x}{2}})\!$
       $+{\frac {A}{n\pi }}(cos({\frac {n\pi }{8}})-cos({\frac {9n\pi }{8}}))sin({\frac {n\pi x}{2}})]\!$

#### Homogeneous Solution

Considering the homogeneous case of our ODE:
$y''-3y'+2y=0\!$
The characteristic equation is
$\lambda ^{2}-3\lambda +2=0\!$
$(\lambda -1)(\lambda -2)=0\!$
$\lambda _{1}=1,\lambda _{1}=2\!$
Therefore our homogeneous solution is of the form
$y_{h}=c_{1}e^{x}+c_{2}e^{2x}\!$

#### Particular Solution

Considering the case with f(x) as excitation
$y''-3y'+2y={\frac {A}{2}}+\sum _{k=1}^{n}{\frac {A}{k\pi }}[(sin({\frac {9k\pi }{8}})-sin({\frac {k\pi }{8}}))cos({\frac {k\pi x}{2}})\!$
       $+(cos({\frac {k\pi }{8}})-cos({\frac {9k\pi }{8}}))sin({\frac {k\pi x}{2}})]\!$
The solution will be of the form
$y_{n}=A_{0}+\sum _{k=1}^{n}A_{k}cos({\frac {k\pi x}{2}})+\sum _{k=1}^{n}B_{k}sin({\frac {k\pi x}{2}})\!$
Taking the derivatives
$y_{n}'=-A_{n}{\frac {\pi }{2}}\sum _{k=2}^{n}ksin({\frac {k\pi x}{2}})+B_{n}{\frac {\pi }{2}}\sum _{k=2}^{n}kcos({\frac {k\pi x}{2}})\!$
$y_{n}''=-A_{n}{\frac {\pi ^{2}}{4}}\sum _{k=3}^{n}k^{2}cos({\frac {k\pi x}{2}})-B_{n}{\frac {\pi ^{2}}{4}}\sum _{k=3}^{n}k^{2}sin({\frac {k\pi x}{2}})\!$
Plugging these back into the ODE:
$-{\frac {\pi ^{2}}{4}}\sum _{k=3}^{n}A_{k}k^{2}cos({\frac {k\pi x}{2}})-{\frac {\pi ^{2}}{4}}\sum _{k=3}^{n}B_{k}k^{2}sin({\frac {k\pi x}{2}})-3[-{\frac {\pi }{2}}\sum _{k=2}^{n}A_{k}ksin({\frac {k\pi x}{2}})\!$
$+{\frac {\pi }{2}}\sum _{k=2}^{n}B_{k}kcos({\frac {k\pi x}{2}})]+2[A_{0}+\sum _{k=1}^{n}A_{k}cos({\frac {k\pi x}{2}})+\sum _{k=1}^{n}B_{k}sin({\frac {k\pi x}{2}})]\!$
$={\frac {A}{2}}+\sum _{k=1}^{n}{\frac {A}{k\pi }}[(sin({\frac {9k\pi }{8}})-sin({\frac {k\pi }{8}}))cos({\frac {k\pi x}{2}})+(cos({\frac {k\pi }{8}})-cos({\frac {9k\pi }{8}}))sin({\frac {k\pi x}{2}})]\!$
Setting the two constants equal
$2A_{0}={\frac {A}{2}}\!$
$A_{0}={\frac {A}{4}}\!$
This is valid for all values of n. Since the coefficients of the excitation $sin({\frac {9k\pi }{8}})-sin({\frac {k\pi }{8}})\!$ and $cos({\frac {k\pi }{8}})-cos({\frac {9k\pi }{8}})\!$ are zero for all even n, then the coefficients $A_{k}\!$ and $B_{k}\!$ will also be zero, so we must only find these coefficients for odd n's. Now carrying out the sum to $n=1\!$ and comparing like terms yields the following sets of equations. Written in matrix form:
       ${\begin{bmatrix}2&0\\\\0&2\end{bmatrix}}*{\begin{bmatrix}A_{1}\\B_{1}\end{bmatrix}}={\begin{bmatrix}\ {\frac {A}{\pi }}(sin({\frac {9\pi }{8}})-sin({\frac {\pi }{8}}))\\\ {\frac {A}{\pi }}(cos({\frac {\pi }{8}})-cos({\frac {9\pi }{8}}))\end{bmatrix}}\!$
Assuming $A=1\!$ this matrix can be solved to obtain
$A_{1}=-0.1218\ ,\ B_{1}=0.2941\!$
For the remaining coefficients to be solved all sums will be used so a more general equation may be written:
       ${\begin{bmatrix}2-{\frac {(\pi k)^{2}}{4}}&{\frac {-3\pi k}{2}}\\{\frac {-3\pi k}{2}}&2-{\frac {(\pi k)^{2}}{4}}\end{bmatrix}}*{\begin{bmatrix}A_{k}\\B_{k}\end{bmatrix}}={\begin{bmatrix}\ {\frac {A}{\pi k}}(sin({\frac {9\pi k}{8}})-sin({\frac {\pi k}{8}}))\\\ {\frac {A}{\pi k}}(cos({\frac {\pi k}{8}})-cos({\frac {9\pi }{8}}))\end{bmatrix}}\!$
Results of these calculations are shown below:
$A={\begin{bmatrix}A_{1}\\A_{2}\\.\\.\\A_{7}\\A_{8}\end{bmatrix}}={\begin{bmatrix}-0.1218\\0\\0.0084\\0\\0.0014\\0\\0.0001\\0\end{bmatrix}},\ B={\begin{bmatrix}B_{1}\\B_{2}\\.\\.\\B_{7}\\B_{8}\end{bmatrix}}={\begin{bmatrix}0.2941\\0\\0.0019\\0\\0.0014\\0\\0.0007\\0\end{bmatrix}}\!$
The solution to the particular case can be written for all n (assuming A=1):

#### General Solution

The general solution is
$y=y_{h}+y_{p}\!$
where
$y_{h}=c_{1}e^{x}+c_{2}e^{2x}\!$
Different coefficients $c_{1}\ ,\ c_{2}\!$ will be calculated for each n. These coefficients are easily solved for by applying the given initial conditions. Below are the calculations for n=2.
$y=c_{1}e^{x}+c_{2}e^{2x}+{\frac {1}{4}}+\sum _{k=1}^{2}A_{k}cos({\frac {k\pi x}{2}})+\sum _{k=1}^{2}B_{k}sin({\frac {k\pi x}{2}})\!$
Applying the first initial condition $y(0)=1\!$
$y(0)=c_{1}+c_{2}+A_{1}+A_{2}=1\!$
Taking the derivative
$y'=c_{1}e^{x}+2c_{2}e^{2x}-\sum _{k=2}^{2}{\frac {k\pi }{2}}A_{k}sin({\frac {k\pi x}{2}})+\sum _{k=2}^{2}{\frac {k\pi }{2}}B_{k}cos({\frac {k\pi x}{2}})\!$
Applying the second initial condition $y'(0)=0\!$
$y'(0)=c_{1}+2c_{2}+{\frac {2\pi }{2}}B_{2}=0\!$
Solving the two equations for two unknowns yields:
$c_{1}=2.2436\ ,\ c_{2}=-1.1218\!$
So the general solution for n=2 is:
$y=2.2436e^{x}-1.1218e^{2x}+{\frac {1}{4}}+\sum _{k=1}^{2}A_{k}cos({\frac {k\pi x}{2}})+\sum _{k=1}^{2}B_{k}sin({\frac {k\pi x}{2}})\!$
Below is a plot showing the general solutions for n=2,4,8:

#### Matlab Plots

Using ode45 the following graph was generated for n=0:
and for n=1