User:Egm4313.s12.team8.tclamb/R6-2

=R6.2 - Fourier Series Expansion=

Problem Statement
Find the Fourier series expansion for $$f(x)$$ on p.9-8 as follows:







Part 1
Develop the Fourier series expansion of $$f(\bar x)$$ Plot $$f(x)$$ and the truncated Fourier series $$f_n(\bar x)$$
 * $$f_n(\bar x) := \bar a_0 + \sum\limits_{k=1}^n \left(\bar a_k \cos{\frac{k \pi \bar x}{L}} + \bar b_k \sin{\frac{k \pi \bar x}{L}} \right)$$

for $$n\,=\,0,\,1,\,2,\,4,\,8$$. Observe the values of $$f_n(\bar x)$$ at the points of discontinuities, and the Gibbs phenomenon. Transform the variable so to obtain the Fourier series expansion of $$f(x)$$.

Part 2
Do the same as above, but using $$f(\tilde x)$$ to obtain the Fourier series expansion of $$f(x)$$; compare to the result obtained above. Plot the truncated Fourier series $$f_n(\tilde x)$$ for $$n\,=\,100,\,200$$:
 * $$f_n(\tilde x) := \tilde a_0 + \sum\limits_{k=1}^n \left(\tilde a_k \cos{\frac{k \pi \tilde x}{L}} + \tilde b_k \sin{\frac{k \pi \tilde x}{L}} \right)$$

Part 1
From inspection of the graph, we determine the value of L:
 * $$L=2$$

To find the coefficients of the Fourier expansion, we use the following formulas:
 * $$\begin{array}{rl}

\bar a_0 &= \frac1{2L}\int_{-L}^L f(\bar x)\, dx \\ \bar a_n &= \frac1L \int_{-L}^L f(\bar x) \cos{\frac{n \pi \bar x}L}\, dx \\ \bar b_n &= \frac1L \int_{-L}^L f(\bar x) \sin{\frac{n \pi \bar x}L}\, dx \end{array}$$

Solving for $$\bar a_0$$:
 * $$\begin{array}{rl}

\bar a_0 &= \frac1{2L}\int_{-L}^L f(\bar x)\, dx \\ &= \frac14 \int_{-2}^2 f(\bar x)\, dx \\ &= \frac14 \left( \int_{-2}^{-1} 0\, dx + \int_{-1}^1 A\, dx + \int_1^2 0\, dx \right) \\ &= \frac14 \int_{-1}^1 A\, dx \\ &= \frac12 A\end{array}$$

Solving for $$\bar a_n$$:
 * $$\begin{array}{rl}

\bar a_n &= \frac1L \int_{-L}^L f(\bar x) \cos{\frac{n \pi \bar x}{L}}\, dx \\ &= \frac12 \int_{-2}^2 f(\bar x) \cos{\frac{n \pi \bar x}2}\, dx \\ &= \frac12 \left( \int_{-2}^{-1} 0 \cos{\frac{n \pi \bar x}2}\, dx + \int_{-1}^1 A \cos{\frac{n \pi \bar x}2}\, dx + \int_1^2 0 \cos{\frac{n \pi \bar x}2}\, dx \right)\\ &= \frac12 A \int_{-1}^1 \cos{\frac{n \pi \bar x}2}\, dx \\ &= \frac{A}{n \pi} \left(\sin{\frac{n\pi}2}-\sin{-\frac{n\pi}2}\right) \\ &= \frac{2A}{n\pi} \sin{\frac{n\pi}2} \end{array}$$

From this, we can notice the following:
 * For even $$n$$, $$\bar a_n = 0$$.
 * For $$n \equiv 1 \mod 4$$, $$\bar a_n = \frac{2A}{n \pi}$$.
 * For $$n \equiv 3 \mod 4$$, $$\bar a_n = -\frac{2A}{n \pi}$$.

Instead of solving for $$\bar b_n$$, we note that $$f(\bar x)$$ is an even function. Sin is an odd function, therefore by orthogonality, $$\bar b_n = 0$$. Evaluating the integral yields the same result.

Taking our results, we insert them into the definition of $$f_n(\bar x)$$:
 * $$\begin{array}{rl}

f_n(\bar x) &= \bar a_0 + \sum\limits_{k=1}^n \left(\bar a_k \cos{\frac{k \pi \bar x}{L}} + \bar b_k \sin{\frac{k \pi \bar x}{L}} \right) \\ &= \frac12 A + \sum\limits_{k=1}^n \bar a_n \cos{\frac{n \pi \bar x}2} \end{array} $$

Using the substitution $$k = 2 m - 1$$ and our observations about $$\bar a_n$$, we obtain: $$f_n(\bar x) = \frac12 A - \sum\limits_{m=1}^{\lfloor \frac{n+1}2 \rfloor} (-1)^m \frac{2A}{(2m-1)\pi} \cos{\frac{(2m-1) \pi \bar x}2}$$

From this, we can generate the following solutions:
 * $$\begin{array}{rl}

f_0(\bar x) &= \frac{A}2 \\ f_1(\bar x) &= \frac{A}{2} + \frac{2 A\cos \left(\frac{\pi x}{2}\right)}{\pi } \\ f_2(\bar x) &= \frac{A}{2} + \frac{2 A\cos \left(\frac{\pi x}{2}\right)}{\pi } \\ f_4(\bar x) &= \frac{A}{2} + \frac{2 A\cos \left(\frac{\pi x}{2}\right)}{\pi }-\frac{2 A\cos \left(\frac{3 \pi    x}{2}\right)}{3 \pi } \\ f_8(\bar x) &= \frac{A}{2} + \frac{2 A\cos \left(\frac{\pi x}{2}\right)}{\pi }-\frac{2 A\cos \left(\frac{3 \pi    x}{2}\right)}{3 \pi }+\frac{2 A\cos \left(\frac{5 \pi  x}{2}\right)}{5 \pi }-\frac{2 A\cos \left(\frac{7 \pi x}{2}\right)}{7 \pi } \end{array}$$

To obtain a solution for $$f_n(x)$$, we observe the following relationship between $$x$$ and $$\bar x$$:
 * $$\bar x = x - \frac54$$

Substituting this into our above result for $$f_n(\bar x)$$, we obtain: $$f_n(x) = \frac12 A - \sum\limits_{m=1}^{\lfloor \frac{n+1}2 \rfloor} (-1)^m \frac{2A}{(2m-1)\pi} \cos{\frac{(2m-1) \pi \left(x - \frac54\right)}2}$$

Plots of $$f_n(\bar x)$$














Part 2
To obtain the Fourier expansion of $$f(\tilde x)$$, the same process as above is followed:

From inspection of the graph, we determine the value of L:
 * $$L=2$$

To find the coefficients of the Fourier expansion, we use the following formulas:
 * $$\begin{array}{rl}

\tilde a_0 &= \frac1{2L}\int_{-L}^L f(\tilde x)\, dx \\ \tilde a_n &= \frac1L \int_{-L}^L f(\tilde x) \cos{\frac{n \pi \tilde x}L}\, dx \\ \tilde b_n &= \frac1L \int_{-L}^L f(\tilde x) \sin{\frac{n \pi \tilde x}L}\, dx \end{array}$$

Solving for $$\tilde a_0$$:
 * $$\begin{array}{rl}

\tilde a_0 &= \frac1{2L}\int_{-L}^L f(\tilde x)\, dx \\ &= \frac14 \int_{-2}^2 f(\tilde x)\, dx \\ &= \frac14 \left( \int_{-2}^{-1} 0\, dx + \int_{-1}^1 A\, dx + \int_1^2 0\, dx \right) \\ &= \frac14 \int_{-1}^1 A\, dx \\ &= \frac12 A\end{array}$$

Instead of solving for $$\tilde a_n$$, we note that $$f(\tilde x)$$ is an odd function. Cos is an even function, therefore by orthogonality, $$\tilde a_n = 0$$. Evaluating the integral yields the same result.

Solving for $$\tilde b_n$$:
 * $$\begin{array}{rl}

\tilde b_n &= \frac1L \int_{-L}^L f(\tilde x) \sin{\frac{n \pi \tilde x}{L}}\, dx \\ &= \frac12 \int_{-2}^2 f(\tilde x) \sin{\frac{n \pi \tilde x}2}\, dx \\ &= \frac12 \left( \int_{-2}^0 0 \sin{\frac{n \pi \tilde x}2}\, dx + \int_0^2 A \sin{\frac{n \pi \tilde x}2}\, dx\right)\\ &= \frac12 A \int_0^2 \sin{\frac{n \pi \tilde x}2}\, dx \\ &= \frac{A}{n \pi} \left(-\cos{n \pi}+\cos0\right) \\ &= \frac{A}{n \pi} \left(1 - \cos{n \pi}\right) \end{array}$$

From this, we can notice the following:
 * For odd $$n$$, $$\tilde b_n = \frac{2A}{n \pi}$$.
 * For even $$n$$, $$\tilde b_n = 0$$.

Taking our results, we insert them into the definition of $$f_n(\tilde x)$$:
 * $$\begin{array}{rl}

f_n(\tilde x) &= \tilde a_0 + \sum\limits_{k=1}^n \left(\tilde a_k \cos{\frac{k \pi \tilde x}{L}} + \tilde b_k \sin{\frac{k \pi \tilde x}{L}} \right) \\ &= \frac12 A + \sum\limits_{k=1}^n \tilde b_n \sin{\frac{n \pi \tilde x}2} \end{array} $$

Using the substitution $$k = 2 m - 1$$ and our observations about $$\tilde b_n$$, we obtain: $$f_n(\tilde x) = \frac12 A + \sum\limits_{m=1}^{\lfloor \frac{n+1}2 \rfloor} \frac{2A}{(2m-1) \pi} \sin{\frac{(2m-1) \pi \tilde x}2}$$

From this, we can generate the following solutions:
 * $$\begin{array}{rl}

f_0(\tilde x) &= \frac{A}2 \\ f_1(\tilde x) &= \frac{A}{2} + \frac{2 A \sin \left(\frac{\pi x}{2}\right)}{\pi } \\ f_2(\tilde x) &= \frac{A}{2} + \frac{2 A \sin \left(\frac{\pi x}{2}\right)}{\pi } \\ f_4(\tilde x) &= \frac{A}{2} + \frac{2 A \sin \left(\frac{\pi x}{2}\right)}{\pi } + \frac{2 A \sin \left(\frac{3 \pi    x}{2}\right)}{3 \pi } \\ f_8(\tilde x) &= \frac{A}{2} + \frac{2 A \sin \left(\frac{\pi x}{2}\right)}{\pi } + \frac{2 A \sin \left(\frac{3 \pi    x}{2}\right)}{3 \pi } + \frac{2 A \sin \left(\frac{5 \pi  x}{2}\right)}{5 \pi } + \frac{2 A \sin \left(\frac{7 \pi x}{2}\right)}{7 \pi } \end{array}$$

To obtain a solution for $$f_n(x)$$, we observe the following relationship between $$x$$ and $$\tilde x$$:
 * $$\tilde x = x - \frac14$$

Substituting this into our above result for $$f_n(\tilde x)$$, we obtain: $$f_n(x) = \frac12 A + \sum\limits_{m=1}^{\lfloor \frac{n+1}2 \rfloor} \frac{2A}{(2m-1) \pi} \sin{\frac{(2m-1) \pi (x - \frac14)}2}$$

This is shown to be equivalent to the above solution by making the following substitution:
 * $$\sin\theta = \cos{\frac{\pi}2 - \theta}$$

Plots of $$f_n(\tilde x)$$














Plots of $$f_n(x)$$














Gibbs Phenomenon
Looking at the above plots, it is clear that the average error is decreasing as a function of $$n$$. However, the overshoot of the Fourier series remains, even as far as $$n = 255$$ as shown below. This overshoot decreases initially, but eventually converges to a limit. This behavior is known as the Gibbs phenomenon. The following table lists approximate average error and the maximum overshoot of the Fourier series as they vary with $$n$$, setting $$A=1$$:

=R6.4 - Solve an ODE with a Fourier Series Excitation=

Problem Statement
Consider the L2-ODE-CC with the window function from R6.2, $$f(x)$$, as excitation:
 * $$y'' - 3y' + 2y = r(x)$$
 * $$r(x) = f(x)$$

And the initial conditions:
 * $$y(0) = 1,\;y'(0) = 0$$

Part 1
Find $$y_n(x)$$ such that:
 * $$y_n'' + a y_n' + b y_n = r_n(x)$$

with the same initial conditions.

Plot $$y_n(x)$$ for $$n=2,\,4,\,8$$, for $$x \in \left[ 0, \, 10 \right]$$.

Part 2
Use the MATLAB command ode45 to integrate the L2-ODE-CC, and plot the numerical solution to compare with the analytical solution.

Solution
When plotting analytical solutions of y(x) over [0,10] the transient response to the excitation is dominated by the steady state response from the homogenous solution.

To more clearly illustrate the convergence of the transient response, we will also plot our solution over the range [-10,0].

Part 1
From R6.2, we know that our excitation function is given by:
 * $$r_n(x) = f_n(x) = \frac12 A + \sum\limits_{m=1}^{\lfloor \frac{n+1}2 \rfloor} \frac{2A}{(2m-1) \pi} \sin{\frac{(2m-1) \pi (x - \frac14)}2}$$

By the Basic Rule and Sum Rule developed in Section 7 of the lecture notes (p.7-2), we know that our particular solution is of the form:
 * $$y_{p,n}(x) = \frac{A}2 + \sum\limits_{i=1}^{\lfloor \frac{n+1}2 \rfloor} \left( J_i \sin{\frac{(2i-1) \pi \left(x - \frac14\right)}{2}} + K_i \cos{\frac{(2i-1) \pi \left(x - \frac14\right)}{2}} \right)$$

And from our work in R3.3, we know that the homogeneous solution is of the form:
 * $$y_h(x) = C_1 e^x + C_2 e^{2x}$$

The cases $$n=0$$ and $$n=1$$ will be worked out below as demonstration, and further cases will be solved using computational software.

Case $$n = 0$$
Setting $$n=0$$ yields the following:
 * $$r_0(x) = \frac12 A$$
 * $$y_{p,0}(x) = \frac{A}4$$

Combining our solution for $$y_{p,0}(x)$$ with $$y_h(x)$$ yields:
 * $$y_0(x) = y_h(x) + y_{p,0}(x) = C_1 e^x + C_2 e^{2x} + \frac{A}4$$

Differentiating this yields:
 * $$y_0'(x) = C_1 e^x + 2 C_2 e^{2x}$$

Applying initial conditions allows us to solve for the homogeneous constants:
 * $$\begin{array}{rl}

y_0(0) &= C_1 + C_2 + \frac{A}4 = 1 \\ y_0'(0) &= C_1 + 2 C_2 = 0 \\ C_1 &= 2 - \frac{A}2 \\ C_2 &= \frac{A}4 - 1 \end{array}$$

Therefore, our final solution is: $$y_0(x) = \frac14 \left( A + (8 - 2 A) e^x + (A - 4) e^{2x} \right)$$

Case $$n = 1$$
Setting $$n=1$$ yields the following:
 * $$r_1(x) = \frac12 A + \frac{2A}{\pi} \sin{\frac{\pi \left(x - \frac14 \right)}2}$$
 * $$y_{p,1}(x) = \frac{A}4 + J \sin{\frac{\pi \left(x - \frac14 \right)}2} + K \cos{\frac{\pi \left(x - \frac14 \right)}2}$$

Differentiating the particular solution yields:
 * $$y_{p,1}'(x) = \frac{J\pi}2 \cos{\frac{\pi \left(x - \frac14 \right)}2} - \frac{K\pi}2 \sin{\frac{\pi \left(x - \frac14 \right)}2}$$
 * $$y_{p,1}''(x) = -\frac{J\pi^2}4 \sin{\frac{\pi \left(x - \frac14 \right)}2} - \frac{K\pi^2}4 \cos{\frac{\pi \left(x - \frac14 \right)}2}$$

Substituting these into the ODE:
 * $$\begin{array}{l}

- \frac{J\pi^2}4 \sin{\frac{\pi \left(x - \frac14 \right)}2} - \frac{K\pi^2}4 \cos{\frac{\pi \left(x - \frac14 \right)}2} \\ \;\;\;\; - \frac{3J\pi}2 \cos{\frac{\pi \left(x - \frac14 \right)}2} + \frac{3K\pi}2 \sin{\frac{\pi \left(x - \frac14 \right)}2} \\ \;\;\;\; + \frac{A}2 + 2J \sin{\frac{\pi \left(x - \frac14 \right)}2} + 2K \cos{\frac{\pi \left(x - \frac14 \right)}2} \\ \;\;\;\;\;\;\;\; = \frac12 A + \frac{2A}{\pi} \sin{\frac{\pi \left(x - \frac14 \right)}2} \end{array}$$

To solve for the coefficients $$J$$ and $$K$$, we set like terms' coefficients equal to each other:
 * $$\begin{array}{rll}

-\frac{J\pi^2}4 + \frac{3K\pi}2 + 2 J &= \left(2 - \frac{\pi^2}4 \right) J + \frac{3\pi}2 K &= \frac{2A}{\pi} \\ -\frac{K\pi^2}4 - \frac{3J\pi}2 + 2 K &= \left(2 - \frac{\pi^2}4 \right) K - \frac{3\pi}2 J &= 0 \\ J &= - \frac{8A\left(\pi^2 - 8\right)}{\pi\left(\pi^4 + 20 \pi^2 + 64\right)} &\\ K &= \frac{48A}{\pi^4 + 20 \pi^2 + 64} & \end{array}$$

As $$J$$ and $$K$$ are rather complex expressions, it is easier to leave them as such and substitute their true values in when necessary. Next, combining our solution for $$y_{p,0}(x)$$ with $$y_h(x)$$ yields:
 * $$y_1(x) = y_h(x) + y_{p,1}(x) = C_1 e^x + C_2 e^{2x} + \frac{A}4 + J \sin{\frac{\pi \left(x - \frac14 \right)}2} + K \cos{\frac{\pi \left(x - \frac14 \right)}2}$$

Differentiating this yields:
 * $$y_1'(x) = C_1 e^x + 2 C_2 e^{2x} + \frac{J\pi}2 \cos{\frac{\pi \left(x - \frac14 \right)}2} - \frac{K\pi}2 \sin{\frac{\pi \left(x - \frac14 \right)}2}$$

Applying initial conditions allows us to solve for the homogeneous constants:
 * $$\begin{array}{rl}

y_1(0) &= C_1 + C_2 + \frac{A}4 + J \sin{\frac{\pi}8} + K \cos{\frac{\pi}8} = 1 \\ y_1'(0) &= C_1 + 2 C_2 + \frac{J\pi}2 \cos{\frac{\pi}8} - \frac{K\pi}2 \sin{\frac{\pi}8} = 0 \\ C_1 &= -\left(\frac{A}2 - 2 + \frac{4 A \cos{\frac{\pi}8}}{\pi^2 + 4} + \frac{8 A \sin{\frac{\pi}8}}{\pi\left(\pi^2 + 4\right)} \right)\\ C_2 &= \frac{A}4 - 1 + \frac{4 A \cos{\frac{\pi}8}}{\pi^2 + 16} + \frac{16 A \sin{\frac{\pi}8}}{\pi\left(\pi^2 + 16\right)} \end{array}$$

Therefore, our final solution is: $$\begin{array}{rl} y_1(x) = & -\left(\frac{A}2 - 2 + \frac{4 A \cos{\frac{\pi}8}}{\pi^2 + 4} + \frac{8 A \sin{\frac{\pi}8}}{\pi\left(\pi^2 + 4\right)} \right) e^x \\ & + \left(\frac{A}4 - 1 + \frac{4 A \cos{\frac{\pi}8}}{\pi^2 + 16} + \frac{16 A \sin{\frac{\pi}8}}{\pi\left(\pi^2 + 16\right)}\right) e^{2x} \\ & + \frac{A}4 - \frac{8A\left(\pi^2 - 8\right)}{\pi\left(\pi^4 + 20 \pi^2 + 64\right)} \sin{\frac{\pi \left(x - \frac14 \right)}2} + \frac{48A}{\pi^4 + 20 \pi^2 + 64} \cos{\frac{\pi \left(x - \frac14 \right)}2} \end{array}$$

Cases $$n = 2, 4, 8$$
Finding the solution with exact coefficients becomes too tedious for cases of n=2 and greater. Instead, Mathematica is used to generate an analytical solution with approximate coefficients.

For n=2 we find the analytical solution to be:

$$\begin{array}{rl} y_2(x) = y_1(x) \approx & 1.30381 e^{1 x}-0.682487 e^{2 x} +0.25 \\ & + 0.038936 \sin (1.5708 x)+0.128673 \cos (1.5708 x) \end{array}$$

For n=4 we find the analytical solution to be:

$$\begin{array}{rl} y_4(x) \approx & 1.29577 e^{1. x} - 0.682847 e^{2. x} + 0.25 \\ & + 0.00705066 \sin (1.1781 -4.71239 x)+0.00493286 \cos (1.1781 -4.71239 x) \\ & + 0.038936 \sin (1.5708 x)+0.128673 \cos (1.5708 x) \end{array}$$

For n=8 we find the analytical solution to be:

$$\begin{array}{rl} y_8(x) \approx &1.31162 e^{1 x}-0.700209 e^{2 x} + 0.25 \\ &+0.0000985159 \sin (9.03208 -36.1283 x) \sin (6.28319 -25.1327 x) \\ &+0.000364302 \sin (8.24668 -32.9867 x) \sin (6.28319 -25.1327 x) \\ &+0.00246643 \sin (7.46128 -29.8451 x) \sin (6.28319 -25.1327 x) \\ &+0.0668894 \sin (6.67588 -26.7035 x) \sin (6.28319 -25.1327 x) \\ &+0.0668894 \sin (6.28319 -25.1327 x) \sin (5.89049 -23.5619 x) \\ &+0.00246643 \sin (6.28319 -25.1327 x) \sin (5.10509 -20.4204 x) \\ &+0.000364302 \sin (6.28319 -25.1327 x) \sin (4.31969 -17.2788 x) \\ &+0.0000985159 \sin (6.28319 -25.1327 x) \sin (3.53429 -14.1372 x) \\ &+0.0000985159 \cos (9.03208 -36.1283 x) \cos (6.28319 -25.1327 x) \\ &+0.000364302 \cos (8.24668 -32.9867 x) \cos (6.28319 -25.1327 x) \\ &+0.00246643 \cos (7.46128 -29.8451 x) \cos (6.28319 -25.1327 x) \\ &+0.0668894 \cos (6.67588 -26.7035 x) \cos (6.28319 -25.1327 x) \\ &+0.0668894 \cos (5.89049 -23.5619 x) \cos (6.28319 -25.1327 x) \\ &+0.00246643 \cos (5.10509 -20.4204 x) \cos (6.28319 -25.1327 x) \\ &+0.000364302 \cos (4.31969 -17.2788 x) \cos (6.28319 -25.1327 x) \\ &+0.0000985159 \cos (3.53429 -14.1372 x) \cos (6.28319 -25.1327 x) \\ &+0.000355107 \sin (9.03208 -36.1283 x) \cos (6.28319 -25.1327 x) \\ &+0.000922816 \sin (8.24668 -32.9867 x) \cos (6.28319 -25.1327 x) \\ &+0.00352533 \sin (7.46128 -29.8451 x) \cos (6.28319 -25.1327 x) \\ &+0.00663447 \sin (6.67588 -26.7035 x) \cos (6.28319 -25.1327 x) \\ &-0.00663447 \sin (5.89049 -23.5619 x) \cos (6.28319 -25.1327 x) \\ &-0.00352533 \sin (5.10509 -20.4204 x) \cos (6.28319 -25.1327 x) \\ &-0.000922816 \sin (4.31969 -17.2788 x) \cos (6.28319 -25.1327 x) \\ &-0.000355107 \sin (3.53429 -14.1372 x) \cos (6.28319 -25.1327 x) \\ &-0.000355107 \sin (6.28319 -25.1327 x) \cos (9.03208 -36.1283 x) \\ &-0.000922816 \sin (6.28319 -25.1327 x) \cos (8.24668 -32.9867 x) \\ &-0.00352533 \sin (6.28319 -25.1327 x) \cos (7.46128 -29.8451 x) \\ &-0.00663447 \sin (6.28319 -25.1327 x) \cos (6.67588 -26.7035 x) \\ &+0.00663447 \sin (6.28319 -25.1327 x) \cos (5.89049 -23.5619 x) \\ &+0.00352533 \sin (6.28319 -25.1327 x) \cos (5.10509 -20.4204 x) \\ &+0.000922816 \sin (6.28319 -25.1327 x) \cos (4.31969 -17.2788 x) \\ &+0.000355107 \sin (6.28319 -25.1327 x) \cos (3.53429 -14.1372 x) \\ \end{array}$$

Positive $$x$$ Plots

 * [[image:y0_pos.png]]
 * [[image:y1_pos.png]]
 * [[image:y2_pos.png]]
 * [[image:y4_pos.png]]
 * [[image:y8_pos.png]]

Negative $$x$$ Plots

 * [[image:y0_neg.png]]
 * [[image:y1_neg.png]]
 * [[image:y2_neg.png]]
 * [[image:y4_neg.png]]
 * [[image:y8_neg.png]]

Part 2
Using the following Matlab function and input allows us to compare the analytical and numerical solutions:

Positive $$x$$ Plots

 * [[image:y,_y2,_y4,_y8_ode45.png]]


 * [[image:y,_y2,_y4,_y8_ode45_zoom1.png]]

The zoomed plot clearly shows that the addition of higher order terms brings the analytical solution closer to y(x).

Negative $$x$$ Plots

 * [[image:Y,_y2,_y4,_y8_neg_NDSolve.png]]


 * [[image:Y,_y2,_y4,_y8_neg_NDSolve_zoom.png‎]]

Again, the addition of higher order terms brings the analytical solution closer to numerical y(x).

=R6.5 - Explore the Sensitivity of a Truncated Taylor Series Excitation and its Solution=

R4.3, p.7c-28
Consider the L2-ODE-CC (5) p.7b-7 with $$log(1+x)$$ as excitation:

$$y''-3y'+2y=r(x)$$

$$r(x)=log(1+x)$$

and the initial conditions

$$y(-\frac34)=1, y'(-\frac34)=0$$

Let $$r_{n}(x)$$ be the truncated Taylor series about $$\hat{x}=0$$, with n terms--which is also the highest degree of the Taylor (power) series--of $$log(1+x)$$.

Explore the sensitivity of the excitation and of the solution for n=11 by adding a small perturbation to the coefficients of the excitation $$r_{n}(x)$$, and propose and explanation.

R4.4, p.7c-29
Extend the accuracy of the solution beyond $$\hat{x}=1$$

Consider the point $$x_{1}=0.9$$ near the brink of non-convergence for the Taylor series of $$log(1+x)$$.

Find the values of $$y_{n}(x_1), y'_{n}(x_1)$$ that will serve as initial conditions for the next iteration to extend the domain accuracy of the analytical solution. Find n sufficiently high so that $$y_{n}(x_1), y'_{n}(x_1)$$ do not differ from the numerical solution by more than $$10^{-5}$$.

Develop $$log(1+x)$$ in Taylor series about $$\hat{x}=1$$.

With $$y_{n}(x)$$ such that:

$$y''_{n}+ay'_{n}+by_{n}=r_{n}(x)$$

For $$x$$ in $$[0.9, 3]$$ with the initial conditions $$y_{n}(x_1), y'_{n}(x_1)$$

For n=11, explore and find the reason why the solution $$y_{n}(x)$$ did not match the numerical solution $$y(x)$$ that serves as the baseline for the comparison.

R4.3
The following MATLAB code generates the numerical solution to the problem:

The following MATLAB function will generate the output, as well as the coefficients, of a series solution to the ODE:

Using the above code, we obtain the following solution and Taylor polynomial for the excitation.
 * $$\begin{array}{rl}y_{11}(x) = &0.045455 x^{11} + 0.70000 x^{10} + 8.0556 x^9 + 77.188 x^8 + 636.32 x^7 + 4520.0 x^6 + 27318 x^5 \\

&+ 137080 x^4 + 549320 x^3 + 164900 x^2 + 3300300 x + 3301100 - 3301800 e^x + 734.89 e^{2x}\end{array}$$
 * $$r_{11}(x) = \frac1{11} x^{11} - \frac1{10} x^{10} + \frac19 x^9 - \frac18 x^8 + \frac17 x^7 - \frac16 x^6 + \frac15 x^5 - \frac14 x^4 + \frac13 x^3 - \frac12 x^2 + x$$



As we know, the excitation blows up beyond the radius of convergence of the Taylor polynomial ($$-1 < x < 1$$). Similarly, the solution blows up at this scale for $$x > 2$$.

Perturbation of 0.01
First, we attempted perturbing the coefficients of $$r_{11}(x)$$ by adding 0.01 to each.
 * $$\begin{array}{rl}

r_{11,pert}(x) = &0.10091 x^{11} - 0.09 x^{10} + 0.12111 x^9 - 0.115 x^8 + 0.15286 x^7 - 0.15667 x^6 \\ &+ 0.21 x^5 - 0.24 x^4 + 0.34333 x^3 - 0.49 x^2 + 1.01 x + 0\end{array} $$

Solving the ODE with this perturbation yields:
 * $$\begin{array}{rl}

y_{11}(x) = &0.050455 x^{11} + 0.7875 x^{10} + 9.0981 x^9 + 87.329 x^8 + 720.49 x^7 + 5119.9 x^6 + 30949 x^5 \\ &+ 155320 x^4 + 622410 x^3 + 1868900 x^2 + 3739600 x + 3740500 - 3741360 e^x + 854.68 e^{2x} \end{array}$$



Adding a positive perturbation to the coefficients of the excitation resulted in a greater divergence of the solution. Noting this, we attempted a negative perturbation.

Perturbation of -0.01
We next attempted perturbing the coefficients of $$r_{11}(x)$$ by adding -0.01 to each.
 * $$\begin{array}{rl}

r_{11,pert}(x) = &0.08091 x^{11} - 0.11 x^{10} + 0.10111 x^9 - 0.135 x^8 + 0.13286 x^7 - 0.17667 x^6 \\ &+ 0.19 x^5 - 0.26 x^4 + 0.32333 x^3 - 0.51 x^2 + 0.99 x + 0\end{array} $$

Solving the ODE with this perturbation yields:
 * $$\begin{array}{rl}

y_{11}(x) = &0.040455 x^{11} + 0.6125 x^{10} + 7.0131 x^9 + 67.046 x^8 + 552.15 x^7 + 3920.2 x^6 + 23687 x^5 \\ &+ 118850 x^4 + 476220 x^3 + 1429900 x^2 + 2861000 x + 2861700 - 2862300 e^x + 615.11 e^{2x} \end{array}$$



As predicted, the accuracy of the solution improved through the addition of a negative perturbation. Noting this, we proceeded to vary the perturbation in an attempt to best match the numerical solution.

Perturbation of -0.035
We finally perturbed the coefficients of $$r_{11}(x)$$ by adding -0.035 to each, as we found through trial and error that this most closely matched the numerical ODE solution over our range.
 * $$\begin{array}{rl}

r_{11,pert}(x) = &0.055909 x^{11} - 0.135 x^{10} + 0.076111 x^9 - 0.16 x^8 + 0.10786 x^7 - 0.20167 x^6 \\ &+ 0.165 x^5 - 0.285 x^4 + 0.29833 x^3 - 0.535 x^2 + 0.965 x + 0\end{array} $$

Solving the ODE with this perturbation yields:
 * $$\begin{array}{rl}

y_{11}(x) = &0.027955 x^{11} + 0.39375 x^{10} + 4.4068 x^9 + 41.693 x^8 + 341.73 x^7 + 2420.6 x^6 + 14609 x^5 \\ &+ 73261 x^4 + 293470 x^3 + 8810600 x^2 + 1762800 x + 1763100 - 1763400 e^x + 315.64 e^{2x} \end{array}$$



This perturbation of -0.035 results in a solution closely matching that of the numerical solution. As shown above, very small perturbations in the coefficients of the excitation resulted in great variety of our solution. In other words, there is great sensitivity in the coefficients of the Taylor polynomial of the excitation.

R4.4


In general, $$y_n(x)$$ will not match the numerical solution, $$y(x)$$, beyond a certain radius of convergence. The solution depends on the excitation, which is a logarithm that we are trying to approximate by a Taylor polynomial of order $$n$$. The shape of a logarithm and a polynomial are fundamentally different. No matter how high we choose $$n$$, it will always diverge. Therefore, the solution must always diverge.