User:Egm4313.s12.team8.tclamb/R5

=R5.8 - Antiderivitave=

Problem Statement
Find the integral
 * $$\int x^n \log(x+1) \, dx$$

using integration by parts, and then with the help of the General Binomial Theorem:
 * $$(x + y)^n = \sum\limits_{k=0}^n \binom{n}{k} x^{n-k} y^k$$

Method 1
For the case of n=0, the integral becomes the integral of $$\log(1+x)$$ which is well known as the following, a result easily obtained by integration by parts: $$\int \log (x+1) \, dx = x \log (x+1) + \log (x+1) - x$$

Integrating by parts, we proceed as follows:

\begin{array}{rl} \int x^n \log (x+1) \, dx & = x^n \left( x \log(1+x) + \log(1+x) - x \right) - \int n x^n \left( x \log(1+x) + \log(1+x) - x \right) \, dx \\ & = x^{n+1} \log (x+1) + x^n \log (x+1) - x^{n+1} - n \int x^n \log (1+x) \, dx - n \int x^{n-1} \log (x+1) \, dx + n \int x^n \, dx \\ (n+1) \int x^n \log (x+1) \, dx & = x^{n+1} \log (x+1) + x^n \log (x+1) - x^{n+1} - n \int x^{n-1} \log (x+1) \, dx + \frac{n}{n+1} x^{n+1} \\ \int x^n \log (x+1) \, dx & = \frac{1}{n+1}\left(x^{n+1} \log (x+1) + x^n \log (x+1) - x^{n+1} - n \int x^{n-1} \log (x+1) \, dx + \frac{n}{n+1} x^{n+1}\right) \end{array} $$

This can be written as the sequence:

\begin{array}{l} R_0(x) = -x + \log (x+1) + x \log (x+1) \\ R_n(x) = \frac{1}{n+1}\left(x^{n+1} \log (x+1) + x^n \log (x+1) - x^{n+1} + \frac{n}{n+1} x^{n+1} - n R_{n-1}\right) \end{array} $$

The first few functions in the sequence are as follows:

\begin{array}{l} R_0(x) = -x + \log (x+1) + x \log (x+1) \\ R_1(x) = \frac12x - \frac14x^2 - \frac12\log(x+1) + \frac12x^2\log(x+1) \\ R_2(x) = -\frac13x + \frac16x^2 - \frac19x^3 + \frac13\log(x+1) + \frac13x^3\log(x+1) \\ R_3(x) = \frac14x - \frac18x^2 + \frac1{12}x^3 - \frac1{16}x^4 - \frac14\log(x+1) + \frac14x^4\log(x+1) \\ R_4(x) = -\frac15x + \frac1{10}x^2 - \frac1{15}x^3 + \frac1{20}x^4 - \frac1{25}x^5 + \frac15\log(x+1) + \frac15x^5\log(x+1) \end{array} $$

From this sequence, we can determine the following form of the solution:

\begin{array}{rl} \int x^n \log (x+1) \, dx & = (-1)^n \frac1{n+1} \log(x+1) + \frac1{n+1} x^{n+1} \log(x+1) + \sum\limits_{k=1}^{n+1}(-1)^{n+k}\frac{x^k}{k(n+1)} \\ & = \frac1{n+1}\left( \left( x^{n+1} + (-1)^n \right) \log (x+1) + \sum\limits_{k=1}^{n+1}\frac{(-1)^{n+k}}{k}x^k \right) \\ & = \frac1{n+1}\left( \left( x^{n+1} + (-1)^n \right) \log (x+1) - x \sum\limits_{k=0}^{n}\frac1{k+1}(-1)^{n-k}x^k \right) \end{array} $$

Unfortunately, the last term in the above solution has withstood every attempt to manipulate it into the form of the general binomial theorem.

Method 2
Beginning with the initial expression:
 * $$\int x^n\log (1+x)dx$$

Integrating by parts yields:
 * $$\frac{1}{n+1}x^{n+1}\log (1+x)-\frac{1}{n+1}\int x^{n+1}\frac{1}{1+x}dx$$

Substituting $$u=1+x$$:
 * $$\frac{1}{n+1}x^{n+1}\log (1+x)-\frac{1}{n+1}\int \frac{1}{u}(u-1)^{n+1}du$$

Expanding binomial with General Binomial Theorem:
 * $$\frac{1}{n+1}x^{n+1}\log (1+x)-\frac{1}{n+1}\int \frac{1}{u}\sum _{i=0}^{n+1} \binom{n+1}{i}u^i(-1)^{(n+1)-i}du$$
 * $$\frac{1}{n+1}x^{n+1}\log (1+x)-\frac{1}{n+1}\int \frac{1}{u}\sum _{i=0}^{n+1} \frac{(n+1)!}{i!((n+1)-i)!}u^i(-1)^{(n+1)-i}du$$

Moving in factor of $$\frac{1}{u}$$:
 * $$\frac{1}{n+1}x^{n+1}\log (1+x)-\frac{1}{n+1}\int \sum _{i=0}^{n+1} \frac{(n+1)!}{i!((n+1)-i)!}u^{i-1}(-1)^{(n+1)-i}du$$

Substituting back for x:
 * $$\frac{1}{n+1}x^{n+1}\log (1+x)-\frac{1}{n+1}\int \sum _{i=0}^{n+1} \frac{(n+1)!}{i!((n+1)-i)!}(1+x)^{i-1}(-1)^{(n+1)-i}dx$$

Pulling out the lowest term:
 * $$\frac{1}{n+1}x^{n+1}\log (1+x)-\frac{1}{n+1}\int \left((1+x)^{-1}(-1)^{n+1}+\sum _{i=1}^{n+1} \frac{(n+1)!}{i!((n+1)-i)!}(1+x)^{i-1}(-1)^{(n+1)-i}\right) \, dx$$

Integrating:
 * $$\frac{1}{n+1}x^{n+1}\log (1+x)-\frac{1}{n+1}\left(\log (1+x)(-1)^{n+1}+\sum _{i=1}^{n+1} \frac{(n+1)!}{i!((n+1)-i)!}\frac{(1+x)^i}{i}(-1)^{(n+1)-i}\right)$$
 * $$\frac{1}{n+1}x^{n+1}\log (1+x)+\frac{1}{n+1}\log (1+x)(-1)^n-\frac{1}{n+1}\sum _{i=1}^{n+1} \frac{(n+1)!}{i!((n+1)-i)!}\frac{(1+x)^i}{i}(-1)^{(n+1)-i}$$
 * $$\frac{1}{n+1}\left(x^{n+1}+(-1)^n\right)\log (1+x)-\frac{1}{n+1}\sum _{i=1}^{n+1} \frac{(n+1)!}{i!((n+1)-i)!}\frac{(1+x)^i}{i}(-1)^{(n+1)-i}$$

Shifting the limits of summation:
 * $$\frac{1}{n+1}\left(x^{n+1}+(-1)^n\right)\log (1+x)-\frac{1}{n+1}\sum _{j=0}^n \frac{(n+1)!}{(j+1)!(n-j)!}\frac{(1+x)^{j+1}}{j+1}(-1)^{n-j}$$
 * $$\frac{1}{n+1}\left(x^{n+1}+(-1)^n\right)\log (1+x)-(1+x)\sum _{j=0}^n \frac{1}{(j+1)^2}\frac{n!}{j!(n-j)!}(1+x)^j(-1)^{n-j}$$

This gives us our final result:
 * $$\int x^n\log (1+x)dx = \frac{1}{n+1}\left(x^{n+1}+(-1)^n\right)\log (1+x)\,-\,(1+x)\sum _{j=0}^n \frac{1}{(j+1)^2}\binom{n}{j}(1+x)^j(-1)^{n-j}$$

Comparing this result to the one obtained above by evaluating for various n, we observe that these are both valid antiderivatives of $$\int x^n\log (1+x)dx$$, differing from each other by only a constant.

=R5.9 - Solve L2-ODE-CC with basis projection of excitation=

Problem Statement
Consider the L2-ODE-CC with $$\log(1+x)$$ as excitation:
 * $$y'' - 3y' + 2y = r(x)$$
 * $$r(x) = \log(1+x)$$

and the initial conditions:
 * $$y(-\frac{3}{4}) = 1, \, y'(-\frac{3}{4}) = 0$$

Part 1
Project the excitation $$r(x)$$ on the polynomial basis:
 * $$\{ b_i(x) = x^i, \, i=0,1,...,n \}$$

i.e. find $$d_i$$ such that:
 * $$r(x) \approx r_n(x) = \sum_{i=0}^n d_i \, x^i$$

for $$x$$ in $$\left[ -\frac{3}{4}, 3 \right]$$, and for n=3,6,9.

Plot $$r(x)$$ and $$r_n(x)$$ to show uniform approximation and convergence.

Note that $$\langle x^i, r \rangle = \int_a^b x^i \log(1+x) \, dx$$

In separate series of plots, compare the approximation of the function $$\log(1+x)$$ by 2 methods: Observe and discuss the pros and cons of each method.
 * Projection on a polynomial basis.
 * Taylor series expansion about $$\hat x = 0$$

Part 2
Find $$y_n(x)$$ such that:
 * $$y_{n}'' + a y_{n}' + b y_n = r_n(x)$$

with the above initial conditions.

Plot $$y_n(x)$$ for n=3,6,9, for x in $$\left[ -\frac{3}{4}, 3 \right]$$.

In a series of separate plots, compare the results obtained with the projected excitation on polynomial basis to those with truncated Taylor series of the excitation. Plot also the numerical solution as a baseline for comparison.

Part 1
To solve for the coefficients of the projection of a function onto an orthonormal basis, we use the following equation:
 * $$\mathbf{ \Gamma c } = \mathbf{ d }$$

Where $$\mathbf \Gamma$$, $$\mathbf c$$ and $$\mathbf d$$ are given by the following:
 * $$\mathbf \Gamma ( \{ b_i \} ) = \left[

\begin{array}{ccccc} \langle b_0, b_0 \rangle & \langle b_0 , b_1 \rangle & \cdots & \langle b_0 , b_{n - 1} \rangle & \langle b_0 , b_n \rangle \\ \langle b_1, b_0 \rangle & \langle b_1 , b_1 \rangle & \cdots & \langle b_1 , b_{n - 1} \rangle & \langle b_1 , b_n \rangle \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ \langle b_{n-1}, b_0 \rangle & \langle b_{n-1} , b_1 \rangle & \cdots & \langle b_{n-1} , b_{n - 1} \rangle & \langle b_{n-1} , b_n \rangle \\ \langle b_n, b_0 \rangle & \langle b_n , b_1 \rangle & \cdots & \langle b_n , b_{n - 1} \rangle & \langle b_n , b_n \rangle \end{array} \right] $$


 * $$\mathbf c = \left[

\begin{array}{c} c_0 \\ c_1 \\ \vdots \\ c_{n-1} \\ c_n \end{array} \right] $$


 * $$\mathbf d = \left[

\begin{array}{c} \langle b_0, f \rangle \\ \langle b_1, f \rangle \\ \vdots \\ \langle b_{n-1}, f \rangle \\ \langle b_n, f \rangle \end{array} \right] $$

And where the scalar product for two functions is defined as:
 * $$\langle f, g \rangle := \int_a^b f(x) g(x) \, dx$$

Using the polynomial basis:
 * $$\{ b_i(x) = x^i, \, i=0,1,...,n \}$$

Over the region $$[a, \, b]$$ where:
 * $$a = -\frac{3}{4} \,, \; b = 3$$

We obtain the following matrix equation:
 * $$\left[

\begin{array}{ccccc} \langle 1, 1 \rangle & \langle 1 , x \rangle & \cdots & \langle 1 , x^{n-1} \rangle & \langle 1 , x^{n} \rangle \\ \langle x, 1 \rangle & \langle x , x \rangle & \cdots & \langle x , x^{n-1} \rangle & \langle x , x^{n} \rangle \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ \langle x^{n-1}, 1 \rangle & \langle x^{n-1} , x \rangle & \cdots & \langle x^{n-1} , x^{n-1} \rangle & \langle x^{n-1} , x^{n} \rangle \\ \langle x^n, 1 \rangle & \langle x^n , x \rangle & \cdots & \langle x^n , x^{n-1} \rangle & \langle x^n , x^n \rangle \end{array} \right] \left[ \begin{array}{c} c_0 \\ c_1 \\ \vdots \\ c_{n-1} \\ c_n \end{array} \right] = \left[ \begin{array}{c} \langle 1, \ln(x+1) \rangle \\ \langle x, \ln(x+1) \rangle \\ \vdots \\ \langle x^{n-1}, \ln(x+1) \rangle \\ \langle x^n, \ln(x+1) \rangle \end{array} \right] $$

Solving with n = 3
Evaluating the scalar products gives us:
 * $$\left[

\begin{array}{cccc} 3.75 & 4.21875 & 9.14063 & 20.1709 \\ 4.21875 & 9.14063 & 20.1709 & 48.6475 \\ 9.14063 & 20.1709 & 48.6475 & 121.47 \\ 20.1709 & 48.6475 & 121.47 & 312.448 \end{array} \right] \mathbf c =\left[ \begin{array}{c} 2.14175 \\ 5.00755 \\ 10.3153 \\ 24.6142 \end{array} \right]$$

Solving for $$\mathbf c$$ then yields:
 * $$\mathbf c = \left[

\begin{array}{c} -0.0388344 \\ 1.12972 \\ -0.439081 \\ 0.0760925 \end{array} \right]$$

This results in the following polynomial:
 * $$r_3(x) = 0.0760925 x^3-0.439081 x^2+1.12972 x-0.0388344$$

Solving with n = 6
Evaluating the scalar products gives us:
 * $$\left[

\begin{array}{ccccccc} 3.75 & 4.21875 & 9.14063 & 20.1709 & 48.6475 & 121.47 & 312.448 \\ 4.21875 & 9.14063 & 20.1709 & 48.6475 & 121.47 & 312.448 & 820.112 \\ 9.14063 & 20.1709 & 48.6475 & 121.47 & 312.448 & 820.112 & 2187.01 \\ 20.1709 & 48.6475 & 121.47 & 312.448 & 820.112 & 2187.01 & 5904.89 \\ 48.6475 & 121.47 & 312.448 & 820.112 & 2187.01 & 5904.89 & 16104.3 \\ 121.47 & 312.448 & 820.112 & 2187.01 & 5904.89 & 16104.3 & 44286.7 \\ 312.448 & 820.112 & 2187.01 & 5904.89 & 16104.3 & 44286.7 & 122640. \end{array} \right] \mathbf c =\left[ \begin{array}{c} 2.14175 \\ 5.00755 \\ 10.3153 \\ 24.6142 \\ 60.4329 \\ 153.96 \\ 400.898 \end{array} \right]$$

Solving for $$\mathbf c$$ then yields:
 * $$\mathbf c = \left(

\begin{array}{c} 0.00585919 \\ 0.982671 \\ -0.557953 \\ 0.464459 \\ -0.275708 \\ 0.0834434 \\ -0.0096586 \end{array} \right)$$

This results in the following polynomial:
 * $$r_6(x) = -0.0096586 x^6+0.0834434 x^5-0.275708 x^4+0.464459 x^3-0.557953 x^2+0.982671 x+0.00585919$$

Solving with n = 9
Evaluating the scalar products gives us:
 * $$\left[

\begin{array}{cccccccccc} 3.75 & 4.21875 & 9.14063 & 20.1709 & 48.6475 & 121.47 & 312.448 & 820.112 & 2187.01 & 5904.89 \\ 4.21875 & 9.14063 & 20.1709 & 48.6475 & 121.47 & 312.448 & 820.112 & 2187.01 & 5904.89 & 16104.3 \\ 9.14063 & 20.1709 & 48.6475 & 121.47 & 312.448 & 820.112 & 2187.01 & 5904.89 & 16104.3 & 44286.7 \\ 20.1709 & 48.6475 & 121.47 & 312.448 & 820.112 & 2187.01 & 5904.89 & 16104.3 & 44286.7 & 122640. \\ 48.6475 & 121.47 & 312.448 & 820.112 & 2187.01 & 5904.89 & 16104.3 & 44286.7 & 122640. & 341641. \\ 121.47 & 312.448 & 820.112 & 2187.01 & 5904.89 & 16104.3 & 44286.7 & 122640. & 341641. & 956594. \\ 312.448 & 820.112 & 2187.01 & 5904.89 & 16104.3 & 44286.7 & 122640. & 341641. & 956594. & 2.69042\times 10^6 \\ 820.112 & 2187.01 & 5904.89 & 16104.3 & 44286.7 & 122640. & 341641. & 956594. & 2.69042\times 10^6 & 7.59648\times 10^6 \\ 2187.01 & 5904.89 & 16104.3 & 44286.7 & 122640. & 341641. & 956594. & 2.69042\times 10^6 & 7.59648\times 10^6 & 2.15234\times 10^7 \\ 5904.89 & 16104.3 & 44286.7 & 122640. & 341641. & 956594. & 2.69042\times 10^6 & 7.59648\times 10^6 & 2.15234\times 10^7 & 6.11717\times 10^7 \end{array} \right] \mathbf c =\left[ \begin{array}{c} 2.14175 \\ 5.00755 \\ 10.3153 \\ 24.6142 \\ 60.4329 \\ 153.96 \\ 400.898 \\ 1062.61 \\ 2854.9 \\ 7754.67 \end{array} \right]$$

Solving for $$\mathbf c$$ then yields:
 * $$\mathbf c = \left[

\begin{array}{c} -0.000966978 \\ 1.00131 \\ -0.477337 \\ 0.299654 \\ -0.304399 \\ 0.334633 \\ -0.237359 \\ 0.09511 \\ -0.0197817 \\ 0.00166379 \end{array} \right]$$

This results in the following polynomial:
 * $$r_9(x) = 0.00166379 x^9-0.0197817 x^8+0.09511 x^7-0.237359 x^6+0.334633 x^5-0.304399 x^4+0.299654 x^3-0.477337 x^2+1.00131 x-0.000966978$$

Comparison of different n
Plotting these three polynomials against the original function yields the following:
 * [[Image:R5.9 n=3,6,9.png]]

Closer inspection between 0.9 and 1.1 shows finer detail:
 * [[Image:R5.9 n=3,6,9 zoomed.png]]

Likewise, between -0.6 and -0.5:
 * [[Image:R5.9 n=3,6,9 zoomed 2.png]]

We can easily see the rapid convergence of this method to the function. Evaluated with n=3, there is an average error of 0.0297816, the difference easily visible. Moving up to n=6, there is only very small error between the function and the polynomial approximation, barely discernible in the unzoomed plot, with the average error being about 0.00365851. At n=9, the error is even smaller, imperceptible when unzoomed and difficult to see even when zoomed, with the average error at about 0.000551377. The average error is roughly halved from n to n+1.

Comparison to Taylor series
The Taylor series about x = 0 is given as follows:
 * $$\log(1+x) \approx \sum_{i=1}^n \frac{(-1)^{i+1}}{i} x^i$$

Generating polynomials for n = 3, 6, and 9:
 * $$\begin{align}

r_{taylor, 3}(x) &= \frac{x^3}{3}-\frac{x^2}{2}+x \\ r_{taylor, 6}(x) &= -\frac{x^6}{6}+\frac{x^5}{5}-\frac{x^4}{4}+\frac{x^3}{3}-\frac{x^2}{2}+x\\ r_{taylor, 9}(x) &= \frac{x^9}{9}-\frac{x^8}{8}+\frac{x^7}{7}-\frac{x^6}{6}+\frac{x^5}{5}-\frac{x^4}{4}+\frac{x^3}{3}-\frac{x^2}{2}+x \end{align}$$

Plotting these against their respective projections:
 * [[Image:R5.9 n=3+taylor.png]]
 * [[Image:R5.9 n=6+taylor.png]]
 * [[Image:R5.9 n=9+taylor.png]]

As we can see, this function is clearly better modeled within this domain by the polynomial obtained via projection than that from its Taylor expansion about 0. While both are accurate for x between -1 and 1, when we look at the graph past 1 for the Taylor polynomial approximations, they rapidly diverge from the actual value of the function. Therefore, while immensely easier to compute, Taylor polynomials are terrible for this range without extending them as in Report 4 by generating a new polynomial wherever the old one diverges and combining the functions piecewise. The major disadvantage of projections, their computational complexity, is easily mitigated nowadays with symbolic math software.

Part 2
From our work in Report 4, we know the homogeneous solution to the ODE is of the form:
 * $$y_h(x) = k_1 e^x + k_2 e^{2x}$$

Also from Report 4, we know that the particular solution to the ODE is of the form:
 * $$y_p(x) = \sum_{i=0}^{\infty} z_i x^i \approx \sum_{i=0}^{n} z_i x^i$$

From Report 4, we know we can solve for the coefficients by solving the matrix equation:
 * $$\mathbf{ A z } = \mathbf c$$

Where $$\mathbf A$$ and $$\mathbf \alpha$$ are given:
 * $$\mathbf A = \begin{bmatrix}

b &     a &  2     &      0 &       0 &         &       0 \\ 0 &     b & 2a     &      6 &       0 &         &       0 \\ 0 &     0 &  b     &     3a &      12 &         &       0 \\ &       &        & \ddots & \ddots  &  \ddots &       0 \\ 0 &     0 &      0 &      0 &       b & a (n-1) & n (n-1) \\ 0 &     0 &      0 &      0 &       0 &       b & a n     \\ 0 &     0 &      0 &      0 &       0 &       0 &   b \end{bmatrix}$$
 * $$\mathbf z = \left[

\begin{array}{c} z_0 \\ z_1 \\ \vdots \\ z_{n-1} \\ z_n \end{array}\right]$$

And $$\mathbf c$$, being the coefficients of our excitation function, determined above:
 * $$\mathbf c = \mathbf \Gamma ^{-1} \mathbf d = \left[

\begin{array}{ccccc} \langle 1, 1 \rangle & \langle 1 , x \rangle & \cdots & \langle 1 , x^{n - 1} \rangle & \langle 1 , x^n \rangle \\ \langle x, 1 \rangle & \langle x , x \rangle & \cdots & \langle x , x^{n - 1} \rangle & \langle x , x^n \rangle \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ \langle x^{n-1}, 1 \rangle & \langle x^{n-1} , x \rangle & \cdots & \langle x^{n-1} , x^{n-1} \rangle & \langle x^{n-1} , x^n \rangle \\ \langle x^n, 1 \rangle & \langle x^n , x \rangle & \cdots & \langle x^n , x^{n-1} \rangle & \langle x^n , x^n \rangle \end{array} \right]^{-1} \left[ \begin{array}{c} \langle 1, \ln(x+1) \rangle \\ \langle x, \ln(x+1) \rangle \\ \vdots \\ \langle x^{n-1}, \ln(x+1) \rangle \\ \langle x^n, \ln(x+1) \rangle \end{array} \right] $$

From our ODE, we determine that $$a=-3$$ and $$b=2$$. Therefore, to solve for the the coefficients of $$y_p,n$$, we solve the following matrix equation:
 * $$\begin{bmatrix}

2 &     -3 &  2     &      0 &       0 &         &       0 \\      0 &      2 & -6     &      6 &       0 &         &       0 \\      0 &      0 &  2     &     -9 &      12 &         &       0 \\        &        &        & \ddots & \ddots  &  \ddots &       0 \\ 0 &     0 &      0 &      0 &       2 & -3 (n-1) & n (n-1) \\ 0 &     0 &      0 &      0 &       0 &       2 & -3 n     \\ 0 &     0 &      0 &      0 &       0 &       0 &   b \end{bmatrix} \mathbf z = \left[ \begin{array}{ccccc} \langle 1, 1 \rangle & \langle 1 , x \rangle & \cdots & \langle 1 , x^{n-1} \rangle & \langle 1 , x^n \rangle \\ \langle x, 1 \rangle & \langle x , x \rangle & \cdots & \langle x , x^{n-1} \rangle & \langle x , x^n \rangle \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ \langle x^{n-1}, 1 \rangle & \langle x^{n-1} , x \rangle & \cdots & \langle x^{n-1} , x^{n-1} \rangle & \langle x^{n-1} , x^n \rangle \\ \langle x^n, 1 \rangle & \langle x^n , x \rangle & \cdots & \langle x^n , x^{n-1} \rangle & \langle x^n , x^n \rangle \end{array} \right]^{-1} \left[ \begin{array}{c} \langle 1, \ln(x+1) \rangle \\ \langle x, \ln(x+1) \rangle \\ \vdots \\ \langle x^{n-1}, \ln(x+1) \rangle \\ \langle x^n, \ln(x+1) \rangle \end{array} \right] $$

We will then apply the following initial conditions to our solution to solve for the constants in the homogeneous solution, thus giving us the final solution:
 * $$y(-\frac{3}{4}) = 1, \, y'(-\frac{3}{4}) = 0$$

Solving with n = 3
Generating our A matrix using the above definition and using our previous value for c, we see:
 * $$\begin{bmatrix}

2 & -3 & 2 &  0 \\  0 &  2 & -6 &  6 \\  0 &  0 &  2 & -9 \\ 0 &  0 &  0 &  2 \end{bmatrix} \mathbf z = \left[ \begin{array}{c} -0.0388344 \\ 1.12972 \\ -0.439081 \\ 0.0760925 \end{array} \right] $$

Then, solving for z, the coefficients of our particular solution:
 * $$\mathbf z = \left[

\begin{array}{c} 0.4875 \\ 0.305723 \\ -0.0483327 \\ 0.0380462 \end{array} \right]$$

We can now write our solution as the combination of the homogeneous and particular:
 * $$y_3(x) = k_1 e^x + k_2 e^{2 x} + 0.0380462 x^3-0.0483327 x^2+0.305723 x+0.4875$$

Applying initial conditions and solving for the constants gives us our final solution:
 * $$y_3(x) = 4.26043 e^x - 5.50107 e^{2 x} +0.0380462 x^3-0.0483327 x^2+0.305723 x+0.4875$$

Solving with n = 6
Generating our A matrix using the above definition and using our previous value for c, we see:
 * $$\begin{bmatrix}

2 & -3 & 2 &  0 &   0 &   0 &  0\\  0 &  2 & -6 &  6 &   0 &   0 &  0\\  0 &  0 &  2 & -9 &  12 &   0 &  0\\ 0 &  0 &  0 &  2 & -12 &  20 &  0\\ 0 &  0 &  0 &  0 &   2 & -15 & 30 \\ 0 &  0 &  0 &  0 &   0 &   2 &-18 \\ 0 & 0  &  0 & 0  &  0  &  0  &  2 \end{bmatrix} \mathbf z = \left[ \begin{array}{c} 0.00585919 \\ 0.982671 \\ -0.557953 \\ 0.464459 \\ -0.275708 \\ 0.0834434 \\ -0.0096586 \end{array} \right] $$

Then, solving for z, the coefficients of our particular solution:
 * $$\mathbf z = \left[

\begin{array}{c} -1.07721 \\ -1.25584 \\ -0.803619 \\ -0.221226 \\ -0.0784793 \\ -0.001742 \\ -0.0048293 \end{array} \right]$$

We can now write our solution as the combination of the homogeneous and particular:
 * $$y_6(x) = k_1 e^x+k_2 e^{2 x}-0.0048293 x^6-0.001742 x^5-0.0784793 x^4-0.221226 x^3-0.803619 x^2-1.25584 x-1.07721$$

Applying initial conditions and solving for the constants gives us our final solution:
 * $$y_6(x) = 5.82483 e^x - 5.52206 e^{2 x}-0.0048293 x^6-0.001742 x^5-0.0784793 x^4-0.221226 x^3-0.803619 x^2-1.25584 x-1.07721$$

Solving with n = 9
Generating our A matrix using the above definition and using our previous value for c, we see:
 * $$\begin{bmatrix}

2 & -3 & 2 &  0 &   0 &   0 &   0 &   0 &   0 & 0 \\  0 &  2 & -6 &  6 &   0 &   0 &   0 &   0 &   0 & 0\\  0 &  0 &  2 & -9 &  12 &   0 &   0 &   0 &   0 & 0\\ 0 &  0 &  0 &  2 & -12 &  20 &   0 &   0 &   0 & 0\\ 0 &  0 &  0 &  0 &   2 & -15 &  30 &   0 &   0 & 0\\ 0 &  0 &  0 &  0 &   0 &   2 & -18 &  42 &   0 & 0\\ 0 &  0 &  0 &  0 &   0 &   0 &   2 & -21 &  56 & 0\\ 0 &  0 &  0 &  0 &   0 &   0 &   0 &   2 & -24 & 72\\ 0 &  0 &  0 &  0 &   0 &   0 &   0 &   0 &   2 & -27 \\ 0&   0&   0&   0&     0&   0&   0&     0&     0& 2 \end{bmatrix} \mathbf z = \left[ \begin{array}{c} -0.000966978 \\ 1.00131 \\ -0.477337 \\ 0.299654 \\ -0.304399 \\ 0.334633 \\ -0.237359 \\ 0.09511 \\ -0.0197817 \\ 0.00166379 \end{array} \right] $$

Then, solving for z, the coefficients of our particular solution:
 * $$\mathbf z = \left[

\begin{array}{c} 149.094 \\ 148.883 \\ 74.23 \\ 24.7691 \\ 6.16541 \\ 1.23731 \\ 0.197483 \\ 0.0336832 \\ 0.0013397 \\ 0.000831895 \end{array} \right]$$

We can now write our solution as the combination of the homogeneous and particular:
 * $$y_9(x) = k_1 e^x+k_2 e^{2 x}+0.000831895 x^9+0.0013397 x^8+0.0336832 x^7+0.197483 x^6+1.23731 x^5+6.16541 x^4+24.7691 x^3+74.23 x^2+148.883 x+149.094$$

Applying initial conditions and solving for the constants gives us our final solution:
 * $$y_9(x) = -144.379 e^x - 5.48955 e^{2 x}+0.000831895 x^9+0.0013397 x^8+0.0336832 x^7+0.197483 x^6+1.23731 x^5+6.16541 x^4+24.7691 x^3+74.23 x^2+148.883 x+149.094$$

Comparison of different n
Using the following MATLAB code to obtain the numeric solution to y, we can then plot it versus our three projected solutions for y.
 * [[Image:R5 y=3,6,9.png]]

At this scale, there isn't much we can qualitatively say about the different approximations. They all appear to fit very well to the numerical solution. Zooming in on the graph at two points, we can begin to see the lines separate:
 * [[Image:R5 y=3,6,9 zoomed.png]]
 * [[Image:R5 y=3,6,9 zoomed 3.png]]

At this scale, we can see the separation between n=3 and n=6,9. This result is as we'd expect, that higher n converge more quickly to the solution. We can zoom even further on the clustered lines:
 * [[Image:R5 y=3,6,9 zoomed 2.png]]
 * [[Image:R5 y=3,6,9 zoomed 4.png]]

Here we observe, as expected, that again, the higher order polynomial more closely fits the graph. This remains true for the entire range of the function.

Comparison to corresponding Taylor series
To generate the Taylor series solutions for n=3,6,9, we reuse the following MATLAB code from Report 4:

Plotting this against the solutions determined above, we obtain the following plots for our three values of n:
 * [[Image:R5 y,n=3.png]]
 * [[Image:R5 y,n=6.png]]
 * [[Image:R5 y,n=9.png]]

It is difficult to determine which method finds a better solution to the ODE from this scale. We can make the following analysis, however: We can zoom in on portions of each graph to determine which method features better performance for a given n:
 * For n=3, we can see than both the projection-derived function and Taylor-derived function perform similarly for x approaching 3 in terms of error. That is to say, neither method remains too close to the numerical solution.
 * For n=6, we can see that the projection-derived function and Taylor-derived function diverge as x approaches 3. Looking at the n=3 graph, we can see that the Taylor-derived function hasn't converged toward the function, whereas the projection-derived function overlaps the numerical solution for this scale.
 * For n=9, we can see little change in the projection-derived function. However, the Taylor-derived function performs worse than for lower n, with large divergence for x > 2.4. This is expected, as the radius of convergence for the excitation function is -1 < x < 1.

Closer Comparison with n=3

 * [[Image:R5 y,n=3 zoomed.png]]
 * [[Image:R5 y,n=3 zoomed 2.png]]

In these plots, we can observe that the projection-derived function has marginally less error than the Taylor-derived function. As the function leaves that radius, the error increases, whereas the projection-derived function has roughly evenly distributed error within this range.

Closer Comparison with n=6

 * [[Image:R5 y,n=6 zoomed 2.png]]
 * [[Image:R5 y,n=6 zoomed.png]]

In both of these plots, we can observe that the error in the projection-derived function is much smaller than that of the Taylor-derived function.

Closer Comparison with n=9

 * [[Image:R5_y,n=9_zoomed.png]]

This is exactly what we expect considering the observed behavior for n=6. And as we observed above, the Taylor-derived function diverges greatly for x > 2.4. Here, we look at x around 0, to observe that even around where the Taylor series is evaluated for the excitation function, our projection-derived function performs better. This leads to a conclusion that projections, while more computationally expensive, perform better than Taylor series for a given domain of interest and the same given n.