# 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:

${\displaystyle y''-3y'+2y=f(x)\!}$

and the initial conditions

${\displaystyle y(0)=1\ ,\ y'(0)=0\!}$

1. Find ${\displaystyle y_{n}(x)\!}$ such that:

${\displaystyle y_{n}''+ay_{n}'+by_{n}=r_{n}(x)\!}$

with the same initial conditions as above.

Plot ${\displaystyle y_{n}(x)\!}$ for ${\displaystyle n=2,4,8\!}$ for x in ${\displaystyle [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: ${\displaystyle n=0,1\!}$

#### Fourier Series

One period of the window function p9.8 is described as follows

${\displaystyle f(x)={\begin{cases}0&\ \ -1.75

From the above intervals one can see that the period, ${\displaystyle p=4\!}$ and therefore ${\displaystyle L=2\!}$ Applying the Euler formulas from ${\displaystyle -1.75}$ to ${\displaystyle 2.25\!}$ the Fourier coefficients are computed:

${\displaystyle a_{0}={\frac {1}{2L}}\int _{-1.75}^{2.25}f(x)\ dx\!}$

${\displaystyle a_{0}={\frac {1}{4}}(\int _{-1.75}^{0.25}0\ dx+\int _{0.25}^{2.25}A\ dx)\!}$

${\displaystyle a_{0}=+{\frac {1}{4}}(0+\int _{0.25}^{2.25}A\ dx)\!}$

${\displaystyle a_{0}={\frac {1}{4}}(2.25A-0.25A)\!}$

${\displaystyle a_{0}={\frac {A}{2}}\!}$

The integral from ${\displaystyle -1.75\!}$ to ${\displaystyle 0.25\!}$ can be omitted from this point on since it is always zero.

${\displaystyle a_{n}={\frac {1}{L}}\int _{0.25}^{2.25}f(x)cos({\frac {n\pi x}{L}})\ dx\!}$

${\displaystyle a_{n}={\frac {1}{2}}\int _{0.25}^{2.25}Acos({\frac {n\pi x}{2}})\ dx\!}$

${\displaystyle a_{n}={\frac {2A}{2n\pi }}(sin({\frac {2.25n\pi }{2}})-sin({\frac {0.25n\pi }{2}})\!}$

${\displaystyle a_{n}={\frac {A}{n\pi }}(sin({\frac {9n\pi }{8}})-sin({\frac {n\pi }{8}})\!}$

and

${\displaystyle b_{n}={\frac {1}{L}}\int _{0.25}^{2.25}f(x)sin({\frac {n\pi x}{L}})\ dx\!}$

${\displaystyle b_{n}={\frac {1}{2}}\int _{0.25}^{2.25}Asin({\frac {n\pi x}{2}})\ dx\!}$

${\displaystyle b_{n}={\frac {2A}{2n\pi }}(cos({\frac {2.25n\pi }{2}})-cos({\frac {0.25n\pi }{2}})\!}$

${\displaystyle b_{n}={\frac {A}{n\pi }}(Acos({\frac {n\pi }{8}})-Acos({\frac {9n\pi }{8}})\!}$

The coefficients give the Fourier series:

${\displaystyle f(x)=a_{0}+\sum _{n=1}^{\infty }[a_{n}cos({\frac {n\pi x}{L}})+b_{n}sin({\frac {n\pi x}{L}})]\!}$

${\displaystyle 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}})\!}$

${\displaystyle +{\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:

${\displaystyle y''-3y'+2y=0\!}$

The characteristic equation is

${\displaystyle \lambda ^{2}-3\lambda +2=0\!}$

${\displaystyle (\lambda -1)(\lambda -2)=0\!}$

${\displaystyle \lambda _{1}=1,\lambda _{1}=2\!}$

Therefore our homogeneous solution is of the form

${\displaystyle y_{h}=c_{1}e^{x}+c_{2}e^{2x}\!}$

#### Particular Solution

Considering the case with f(x) as excitation

${\displaystyle 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}})\!}$

${\displaystyle +(cos({\frac {k\pi }{8}})-cos({\frac {9k\pi }{8}}))sin({\frac {k\pi x}{2}})]\!}$

The solution will be of the form

${\displaystyle 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

${\displaystyle 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}})\!}$

${\displaystyle 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:

${\displaystyle -{\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}})\!}$

${\displaystyle +{\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}})]\!}$

${\displaystyle ={\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

${\displaystyle 2A_{0}={\frac {A}{2}}\!}$

${\displaystyle A_{0}={\frac {A}{4}}\!}$

This is valid for all values of n. Since the coefficients of the excitation ${\displaystyle sin({\frac {9k\pi }{8}})-sin({\frac {k\pi }{8}})\!}$ and ${\displaystyle cos({\frac {k\pi }{8}})-cos({\frac {9k\pi }{8}})\!}$ are zero for all even n, then the coefficients ${\displaystyle A_{k}\!}$ and ${\displaystyle B_{k}\!}$ will also be zero, so we must only find these coefficients for odd n's. Now carrying out the sum to ${\displaystyle n=1\!}$ and comparing like terms yields the following sets of equations. Written in matrix form:

${\displaystyle {\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 ${\displaystyle A=1\!}$ this matrix can be solved to obtain

${\displaystyle 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:

${\displaystyle {\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:

${\displaystyle 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):

      ${\displaystyle y_{n}={\frac {1}{4}}+\sum _{k=1}^{n}A_{k}cos({\frac {k\pi x}{2}})+\sum _{k=1}^{n}B_{k}sin({\frac {k\pi x}{2}})\!}$


#### General Solution

The general solution is

${\displaystyle y=y_{h}+y_{p}\!}$

where

${\displaystyle y_{h}=c_{1}e^{x}+c_{2}e^{2x}\!}$

Different coefficients ${\displaystyle 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.

${\displaystyle 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 ${\displaystyle y(0)=1\!}$

${\displaystyle y(0)=c_{1}+c_{2}+A_{1}+A_{2}=1\!}$

Taking the derivative

${\displaystyle 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 ${\displaystyle y'(0)=0\!}$

${\displaystyle y'(0)=c_{1}+2c_{2}+{\frac {2\pi }{2}}B_{2}=0\!}$

Solving the two equations for two unknowns yields:

${\displaystyle c_{1}=2.2436\ ,\ c_{2}=-1.1218\!}$

So the general solution for n=2 is:

${\displaystyle 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