User:Egm4313.s12.team11.perez.gp/R5.9

R5.9
Solved by: Gonzalo Perez

Problem Statement
Consider the L2-ODE-CC (5) p.7b-7 with $$ log(1+x) \! $$ as excitation:

$$ y''-3y'+2y=r(x) \! $$  (5) p.7b-7

$$ r(x)=log(1+x) \! $$    (1) p.7c-28

and the initial conditions

$$ y(\frac{-3}{4})=1, y'(\frac{-3}{4})=0 \! $$.

Part A
Project the excitation $$ r(x) \! $$ on the polynomial basis

$$ {b_j (x) = x^j, j=0, 1, ..., n} \! $$   (1)

i.e., find $$ d_j \! $$ such that

$$ r(x) \approx r_n (x) = \sum_{j=0}^{n} d_j x^j \! $$   (2)

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

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

Note that:

$$ \left \langle x^i,r \right \rangle = \int_{a}^{b} x^i log(1+x) dx \! $$    (3)

Solution
To solve this problem, it is important to know that the scalar product is defined as the following:

$$ \left \langle b_0, b_0 \right \rangle = \int x^0\cdot x^0 dx \! $$.

Therefore, it follows that:

$$ \left \langle b_i,b_j \right \rangle = \int x^i\cdot x^j dx \! $$, where $$ b_i (x)=x^i \! $$ and $$ b_j (x) = x^j \! $$.

We know that if $$ b_1, b_2 \! $$ are linearly independent, then by theorem on p.7c-37, the matrix is solvable.

According to this and (3)p.8-14:

If $$ \Gamma \neq 0 \Rightarrow \Gamma^{-1} \! $$ exists $$ \Rightarrow c= \Gamma^{-1}d \! $$.      (3)p.8-14

Now let's define the Gram matrix $$ \Gamma \! $$ as a function of $$ b_i \! $$:

$$ \Gamma (b_i)=\begin{bmatrix} \left \langle b_0,b_0 \right \rangle & \left \langle b_0,b_1 \right \rangle & ... & \left \langle b_0,b_n \right \rangle\\ ... & ... & ... & ...\\ ... & ... & ... & ...\\ \left \langle b_n,b_0 \right \rangle & \left \langle b_n,b_1 \right \rangle & ... & \left \langle b_n,b_n \right \rangle \end{bmatrix} \! $$      (1)p.8-13

Defining the "d" matrix as was done in (3)p.8-13, we get:

$$ d = \begin{Bmatrix} \left \langle b_0,r \right \rangle\\ \left \langle b_1,r \right \rangle\\ ...\\

\left \langle b_n,r \right \rangle\end{Bmatrix} \! $$.       (3)p.8-13

And according to (1)p.8-15: $$ r_n(x) = \sum_{0}^{n}c_i x^i \! $$         (1)p.8-15

Now, we can find the values to compare $$ r_n \! $$ to $$ y \! $$.

Using Matlab, this is the code that was used to produce the results:

The Matlab code above produced the following graph:

Where $$ r_n(x) \! $$ is represented by the dashed line and the approximation,$$ y(x) \! $$, is represented by the red line. This code can work for all n values.

Part B
In a seperate series of plots, compare the approximation of the function $$ \log(x+1) \!$$ by Taylor series expansion about $$ x=0 \!$$.

Where: $$ f(x)= \sum_{n=0}^\infty \frac{f^{(n)}(\hat x)}{n!}(x- \hat x)^n \!$$

Solution
For n=1:

$$ \log(x+1) = \frac{x}{\log(10)} \! $$

For n=2:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)} \! $$

For n=3:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)} \! $$

For n=4:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)} \!$$

For n=5:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)} \! $$

For n=6:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)} \! $$

For n=7:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)} \!$$

For n=8:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)} \! $$

For n=9:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)}+\frac{x^9}{\log(10^9)} \! $$

For n=10:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)}+\frac{x^9}{\log(10^9)}-\frac{x^{10}}{\log(10^{10})} \! $$

For n=11:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)}+\frac{x^9}{\log(10^9)}-\frac{x^{10}}{\log(10^{10})}+\frac{x^{11}}{\log(10^{11})} \!$$

For n=12:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)}+\frac{x^9}{\log(10^9)}-\frac{x^{10}}{\log(10^{10})}+\frac{x^{11}}{\log(10^{11})}\!$$ $$ -\frac{x^{12}}{\log(10^{12})} \! $$

For n=13:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)}+\frac{x^9}{\log(10^9)}-\frac{x^{10}}{\log(10^{10})}+\frac{x^{11}}{\log(10^{11})}\!$$ $$ -\frac{x^{12}}{\log(10^{12})}+\frac{x^{13}}{\log(10^{13})} \! $$

For n=14:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)}+\frac{x^9}{\log(10^9)}-\frac{x^{10}}{\log(10^{10})}+\frac{x^{11}}{\log(10^{11})}\!$$ $$ -\frac{x^{12}}{\log(10^{12})}+\frac{x^{13}}{\log(10^{13})}-\frac{x^{14}}{\log(10^{14})} \! $$

For n=15:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)}+\frac{x^9}{\log(10^9)}-\frac{x^{10}}{\log(10^{10})}+\frac{x^{11}}{\log(10^{11})}\!$$ $$ -\frac{x^{12}}{\log(10^{12})}+\frac{x^{13}}{\log(10^{13})}-\frac{x^{14}}{\log(10^{14})}+\frac{x^{15}}{\log(10^{15})} \! $$

For n=16:

$$ \log(x+1) = \frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)}+\frac{x^9}{\log(10^9)}-\frac{x^{10}}{\log(10^{10})}+\frac{x^{11}}{\log(10^{11})}\!$$ $$ -\frac{x^{12}}{\log(10^{12})}+\frac{x^{13}}{\log(10^{13})}-\frac{x^{14}}{\log(10^{14})}+\frac{x^{15}}{\log(10^{15})}-\frac{x^{16}}{\log(10^{16})} \!$$

Using Matlab to plot the graph:

Part 2
Find $$ y_n (x) \! $$ such that:

$$ y_n'' + ay_n'+by_n = r_n (x) \! $$   (1) p.7c-27

with the same initial conditions as in (2) p.7c-28.

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

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.

Solution
First, we find the homogeneous solution to the ODE:

The characteristic equation is:

$$\lambda^2-3\lambda+2=0\!$$

$$(\lambda-2)(\lambda-1)=0\!$$

Then, $$\lambda=1,2\!$$

Therefore the homogeneous solution is:

$$y_h=C_1e^(2x)+c_2e^x\!$$

Now to find the particulate solution

For n=3:

$$ r(x)=\sum_{0}^{n}-\frac{(-1)^nx^n}{n\ln (10)} \!$$

$$ r(x)=\frac{x}{\ln(10)}-\frac{x^2}{2\ln(10)}+\frac{x^3}{3\ln(10)} \!$$

We can then use a matrix to organize the known coefficients:

$$ \begin{bmatrix} 2 &-3  &2  &0  & 0\\ 0&  2  &-6  &6  & 0\\ 0&  0&  2  &-9  &12  \\ 0&  0&  0&  2  &-12\\ 0&  0&  0& 0 &  2  \\  \end{bmatrix} \begin{bmatrix} K_{0} \\ K_{1} \\ K_{2} \\ K_{3} \end{bmatrix} = \begin{bmatrix} 0 \\ \frac{1}{ln(10)} \\ \frac{1}{2ln(10)} \\ \frac{1}{3ln(10)} \end{bmatrix}\!$$

Then, using MATLAB and the backlash operator we can solve for these unknowns:

Therefore

$$ y_{p4}=4.0444+3.7458x+1.5743x^2+0.3981x^3+0.0543x^4 \!$$

Superposing the homogeneous and particulate solution we get

$$ y_{n}=4.0444+3.7458x+1.5743x^2+0.3981x^3+0.0543x^4+C_1e^{2x}+C_2e^{x} \!$$

Differentiating:

$$y'_{n}=3.7458+3.1486x+1.1943x^2+0.2172x^3+2C_1e^{2x}+C_2e^{x}\!$$ Evaluating at the initial conditions:

$$y(-0.75)=0.9698261719+0.231301601C_!+0.4723665527C_2=1\!$$

$$y'(-0.75)=1.9645125+0.4462603203C_1+0.4723665527C_2\!$$

We obtain: $$ C_1=-4.46\!$$ $$ C_2=0.055 \!$$ Finally we have: $$ y_{n}=4.0444+3.7458x+1.5743x^2+0.3981x^3+0.0543x^4-4.46e^{2x}+0.055e^{x} \!$$

For n=6:

$$ r(x)=\sum_{0}^{n}-\frac{(-1)^nx^n}{n\ln (10)} \!$$

$$ r(x)=\frac{x}{\ln(10)}-\frac{x^2}{2\ln(10)}+\frac{x^3}{3\ln(10)}-\frac{x^4}{4\ln(10)}+\frac{x^5}{5\ln(10)}-\frac{x^6}{6\ln(10)} \!$$

We can then use a matrix to organize the known coefficients:

$$ \begin{bmatrix} 2 &-3  &2  &0  & 0 &0 &0 &0\\ 0&  2  &-6  &6  & 0 &0 &0 &0\\ 0&  0&  2  &-9  &12  &0 &0 &0\\ 0&  0&  0&  2  &-12 &20 &0 &0 \\ 0&  0&  0& 0 &  2 &-15 &30 &0\\ 0 &0 &0 &0 &0 &2 &-18 &42\\ 0 &0 &0 &0 &0 &0  &2 &-21\\ 0 &0 &0 &0 &0 &0 &0 &2\\  \end{bmatrix} \begin{bmatrix} K_{0} \\ K_{1} \\ K_{2} \\ K_{3} \\ K_{4} \\ K_{5} \\ K_{6} \end{bmatrix} \begin{bmatrix} 0 \\ \frac{1}{ln(10)} \\ \frac{1}{2ln(10)} \\ \frac{1}{3ln(10)} \\ \frac{1}{4ln(10)} \\ \frac{1}{5ln(10)} \\ \frac{1}{6ln(10)} \end{bmatrix}\!$$

Then, using MATLAB and the backlash operator we can solve for these unknowns:

Therefore

$$ y_{p7}=377.4833+375.3933x+185.6066x^2+60.5479x^3+14.4946x^4+2.6492x^5+0.3619x^6+0.0310x^7 \!$$

Superposing the homogeneous and particulate solution we get

$$ y_{n}=377.4833+375.3933x+185.6066x^2+60.5479x^3+14.4946x^4+2.6492x^5+0.3619x^6+0.0310x^7+C_1e^{2x}+c_2e^x \!$$

Differentiating:

$$y'_{n}=375.3933+371.213x+181.644x^2+57.9784x^3+13.46x^4+2.1714x^5+0.214x^6+2C_1e^{2x}+C_2e^x\!$$ Evaluating at the initial conditions:

$$y(-0.75)=178.816+0.2231301601C_!+0.4723665527C_2=1\!$$

$$y'(-0.75)=178.413+0.4462603203C_1+0.4723665527C_2\!$$

We obtain: $$ C_1=-2.6757\!$$ $$ C_2=-375.173 \!$$ Finally $$ y_{n}=377.4833+375.3933x+185.6066x^2+60.5479x^3+14.4946x^4+2.6492x^5+0.3619x^6+0.0310x^7+-2.6757e^{2x}-375.173e^x \!$$

For n=9:

$$ r(x)=\sum_{0}^{n}-\frac{(-1)^nx^n}{n\ln (10)} \!$$

$$ r(x)=\frac{x}{\log(10)}-\frac{x^2}{\log(10^2)}+\frac{x^3}{\log(10^3)}-\frac{x^4}{\log(10^4)}+\frac{x^5}{\log(10^5)}-\frac{x^6}{\log(10^6)}+\frac{x^7}{\log(10^7)}-\frac{x^8}{\log(10^8)}+\frac{x^9}{\log(10^9)} \! $$

We can then use a matrix to organize the known coefficients:

$$ \begin{bmatrix} K_{0} \\ K_{1} \\ K_{2} \\ K_{3} \\ K_{4} \\ K_{5} \\ K_{6} \\ K_{7} \\ K_{8} \\ K_{9} \end{bmatrix} = \begin{bmatrix} 0 \\ \frac{1}{ln(10)} \\ \frac{1}{2ln(10)} \\ \frac{1}{3ln(10)} \\ \frac{1}{4ln(10)} \\ \frac{1}{5ln(10)} \\ \frac{1}{6ln(10)} \\ \frac{1}{7ln(10)} \\ \frac{1}{8ln(10)} \\ \frac{1}{9ln(10)} \end{bmatrix}\!$$

Then, using MATLAB and the backlash operator we can solve for these unknowns:



Therefore

$$ y_{p11}=1753158.594+1752673.419x+875851.535x^2+291627.134x^3+72745.1129x^4+14484.362x^5+2392.510x^6+335.632x^7+40.417x^8\!$$ $$+4.1499x^9+0.3474x^(10)+0.0197x^(11) \!$$

Superposing the homogeneous and particulate solution we get

$$ y_{n}=1753158.594+1752673.419x+875851.535x^2+291627.134x^3+72745.1129x^4+14484.362x^5+2392.510x^6+335.632x^7+40.417x^8\!$$ $$+4.1499x^9+0.3474x^(10)+0.0197x^(11)+C_1e^{2x}+C_2e^(x) \!$$

Differentiating:

$$y'_{n}=0.2167 x^10+3.474 x^9+37.3491 x^8+323.336 x^7+2349.42 x^6+14355.1 x^5+72421.8 x^4+290980. x^3+874881. x^2\!$$ $$+1.7517x10^6 x+1.75267x10^6+2C_1e^{2x}+C_2e^x\!$$ Evaluating at the initial conditions:

$$y(-0.75)=828254+0.2231301601C_!+0.4723665527C_2=1\!$$

$$y'(-0.75)=828145+0.4462603203C_1+0.4723665527C_2=0\!$$

We obtain: $$ C_1=-484.022\!$$ $$ C_2=-1753750 \!$$ Finally $$ y_{n}=1753158.594+1752673.419x+875851.535x^2+291627.134x^3+72745.1129x^4+14484.362x^5+2392.510x^6+335.632x^7+40.417x^8\!$$ $$+4.1499x^9+0.3474x^(10)+0.0197x^(11)-484.022e^{2x}-1753750e^x \!$$

Here is the graph for this problem using Matlab: