User:Egm4313.s12.team8.colocar/R4.3

Problem
Consider the L2-ODE-CC below with $$ \displaystyle log(1+x)$$ as excitation:

$$ \displaystyle y''-3y'+2y = r(x)$$ $$ \displaystyle r(x) = log(1+x)$$

and the initial conditions $$ \displaystyle y(-\frac3{4})=1, y'(-\frac3{4})=0 $$

1. Develop $$ \displaystyle log(1+x)$$ in Taylor series about $$ \displaystyle \widehat{x}=0$$ to reproduce the figure below



2. Let $$ \displaystyle r_n(x)$$ be truncated Taylor series, with n terms--which is also the highest degree of the Taylor (power) series--of $$ \displaystyle log(1+x)$$. Find $$ \displaystyle y_n(x),$$ for n = 4, 7, 11, such that: $$ \displaystyle y_{n}''+ay_{n}'+by_{n}=r_n(x)$$ with the same initial conditions mentioned earlier. Plot $$ \displaystyle y_{n}(x)$$ for n = 4, 7, 11 for $$ \displaystyle x$$ in $$ \displaystyle [-\frac3{4},3].$$

3. Use the matlab command ode45 to integrate numerically the given equation to obtain the numerical solution for $$ \displaystyle y(x).$$ Plot $$ \displaystyle y(x)$$ in the same figure with $$ \displaystyle y_n(x).$$

Solution
1. The Taylor series about a point $$ \displaystyle \hat{x} $$ is defined as $$ \displaystyle  f(x) = \sum_{n=0}^\infty \frac{f^{n} (\hat x)}{n!} (x - \hat x)^n $$

For $$ \displaystyle \hat{x}=0, $$ we can expand the series as $$ \displaystyle f(x) = \sum_{n=0}^\infty \frac{f^{n}(0)}{n!} x^n = \frac{f^{0}(0)}{0!} x^0 + \frac{f^{1}(0)}{1!} x^1 + \frac{f^{2}(0)}{2!} x^2 + \frac{f^{3}(0)}{3!} x^3 + \cdots + \frac{f^{n}(0)}{n!} x^n $$

Deriving $$ \displaystyle ln(1+x) $$ yields $$ \displaystyle \frac{1}{x+1} $$

Plugging the derivative into the expanded series yields $$ \displaystyle log(1+x) = \sum_{n=0}^\infty \frac{f^{0}(0)}{n!}x^0 = \frac{1}{0!}ln(1)x^0 + \frac{1}{1!}\frac{1}{0+1}x^1 - \frac{1}{2!}\frac{1}{(0+1)^2}x^2 + \frac{1}{3!}\frac{2}{(0+1)^3}x^3 \cdots + \frac{1}{n!}\frac{f^n(0)}{(1)^n}x^n $$

Simplified gives us $$ \displaystyle ln(1+x) = \sum_{n=0}^\infty \frac{f^{0}(0)}{n!}x^0 = 0+ \frac{x^1}{1} - \frac{x^2}{2} + \frac{x^3}{3} + \cdots + \frac{x^n}{n} $$

Or from the Mercator series, $$\log(1+x)=\sum_{n=1}^\infty \frac{(-1)^{n+1}}{n} x^n = x - \frac{x^2}{2} + \frac{x^3}{3} - \cdots \quad$$ so, T4 (n = 4) $$ \displaystyle ln(1+x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4}$$

T7 (n = 7) $$ \displaystyle ln(1+x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \frac{x^5}{5} - \frac{x^6}{6} + \frac{x^7}{7}$$

T11 (n = 11) $$ \displaystyle ln(1+x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \frac{x^5}{5} - \frac{x^6}{6} + \frac{x^7}{7} - \frac{x^8}{8} + \frac{x^9}{9} - \frac{x^{10}}{10} + \frac{x^{11}}{11}$$

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

Creating a function in MATLAB, we can code and plot

2. To find $$ \displaystyle y_n(x), $$ we must first determine the homogeneous and particular solutions. We know the characteristic equation to be $$ \displaystyle \lambda^2 -3\lambda + 2 = 0, $$ so $$ \displaystyle (\lambda - 2)(\lambda - 1) = 0, $$

Knowing $$ \displaystyle \lambda = 1,2, $$ the homogeneous solution is defined as $$ \displaystyle y_h = c_1e^x + c_2e^{2x}$$

n = 4 The particular solution for n = 4 can be obtained from the following: $$ \displaystyle y_p = K_4x^4 + K_3x^3 + K_2x^2 + K_1x^1 + K_0. $$ Also, $$ \displaystyle y_p' = 4K_4x^3 + 3K_3x^2 + 2K_2x + K_1 $$ and $$ \displaystyle y_p'' = 12K_4x^2 + 6K_3x + 2K_2. $$

Plugging back into the given ODE, and equating to the excitation gives us $$ \displaystyle (12K_4x^2 + 6K_3x + 2K_2) - 3(4K_4x^3 + 3K_3x^2 + 2K_2x + K_1) + 2(K_4x^4 + K_3x^3 + K_2x^2 + K_1x^1 + K_0) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} $$

Simplified, $$ \displaystyle (12K_4x^2 + 6K_3x + 2K_2) - (12K_4x^3 + 9K_3x^2 + 6K_2x + 3K_1) + (2K_4x^4 + 2K_3x^3 + 2K_2x^2 + 2K_1x^1 + 2K_0) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} $$

Creating a matrix for Matlab to solve for the unknown values of K $$ \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 \\ K_4 \end{bmatrix} =

\begin{bmatrix} 0 \\ 1 \\ -\frac{1}{2} \\ \frac{1}{3} \\ -\frac{1}{4} \end{bmatrix}$$



Now, we have $$ \displaystyle y_p = 0.0543x^4 + 0.3981x^3 + 1.5743x^2 + 3.7458x^1 + 4.0444 $$ and our final solution is $$ \displaystyle y_n(x) = c_1e^x + c_2e^{2x} + 0.0543x^4 + 0.3981x^3 + 1.5743x^2 + 3.7458x^1 + 4.0444 $$

Evaluating at our initial conditions gives $$ \displaystyle y_n(-\frac3{4}) = c_1e^{-\frac3{4}} + c_2e^{2(-\frac3{4})} + 0.0543(-\frac3{4})^4 + 0.3981(-\frac3{4})^3 + 1.5743(-\frac3{4})^2 + 3.7458(-\frac3{4})^1 + 4.0444 = 1 $$ and

$$ \displaystyle y'_n(-\frac3{4}) = c_1e^{-\frac3{4}} + 2c_2e^{2(-\frac3{4})} + 4(0.0543)(-\frac3{4})^3 + 3(0.3981)(-\frac3{4})^2 + 2(1.5743)(-\frac3{4}) + 3.7458 = 0 $$

Solving for the constants gives us $$ \displaystyle c_1 = -4.4579 $$ $$ \displaystyle c_2 = 0.0526 $$

Therefore, $$ \displaystyle y_n(x) = -4.4579e^x + 0.0526e^{2x} + 0.0543x^4 + 0.3981x^3 + 1.5743x^2 + 3.7458x^1 + 4.0444 $$ and

n = 7 The particular solution for n = 7 can be obtained from the following: $$ \displaystyle y_p = K_7x^7 + K_6x^6 + K_5x^5 + K_4x^4 + K_3x^3 + K_2x^2 + K_1x^1 + K_0. $$ Also, $$ \displaystyle y_p' = 7K_7x^6 + 6K_6x^5 + 5K_5x^4 + 4K_4x^3 + 3K_3x^2 + 2K_2x + K_1 $$ and $$ \displaystyle y_p'' = 42K_7x^5 + 30K_6x^4 + 20K_5x^3 + 12K_4x^2 + 6K_3x + 2K_2. $$

Plugging back into the given ODE, and equating to the excitation gives us $$ \displaystyle (42K_7x^5 + 30K_6x^4 + 20K_5x^3 + 12K_4x^2 + 6K_3x + 2K_2) - 3(7K_7x^6 + 6K_6x^5 + 5K_5x^4 + 4K_4x^3 + 3K_3x^2 + 2K_2x + K_1) + \cdots $$ $$ \displaystyle 2(K_7x^7 + K_6x^6 + K_5x^5 + K_4x^4 + K_3x^3 + K_2x^2 + K_1x^1 + K_0) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \frac{x^5}{5} - \frac{x^6}{6} + \frac{x^7}{7} $$

Simplified, $$ \displaystyle (42K_7x^5 + 30K_6x^4 + 20K_5x^3 + 12K_4x^2 + 6K_3x + 2K_2) - (21K_7x^6 + 18K_6x^5 + 15K_5x^4 + 12K_4x^3 + 9K_3x^2 + 6K_2x + 3K_1) + \cdots $$ $$ \displaystyle (2K_7x^7 + 2K_6x^6 + 2K_5x^5 + 2K_4x^4 + 2K_3x^3 + 2K_2x^2 + 2K_1x^1 + 2K_0) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \frac{x^5}{5} - \frac{x^6}{6} + \frac{x^7}{7} $$

Creating a matrix for Matlab to solve for the unknown values of K $$ \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 \\ K_7 \end{bmatrix} =

\begin{bmatrix} 0 \\ 1 \\ -\frac{1}{2} \\ \frac{1}{3} \\ -\frac{1}{4} \\ \frac{1}{5} \\ -\frac{1}{6} \\ \frac{1}{7} \end{bmatrix}$$



Now, we have $$ \displaystyle y_p = 0.0310x^7 + 0.3619x^6 + 2.6492x^5 + 14.4946x^4 + 60.5479x^3 + 185.6066x^2 + 375.3933x + 377.4833 $$

and our final solution is $$ \displaystyle y_n(x) = c_1e^x + c_2e^{2x} + 0.0310x^7 + 0.3619x^6 + 2.6492x^5 + 14.4946x^4 + 60.5479x^3 + 185.6066x^2 + 375.3933x + 377.4833 $$

Evaluating at our initial conditions gives $$ \displaystyle y_n(-\frac3{4}) = c_1e^{-\frac3{4}} + c_2e^{2(-\frac3{4})} + 0.0310(-\frac3{4})^7 + 0.3619(-\frac3{4})^6 + 2.6492(-\frac3{4})^5 + \cdots $$ $$ \displaystyle 14.4946(-\frac3{4})^4 + 60.5479(-\frac3{4})^3 + 185.6066(-\frac3{4})^2 + 375.3933(-\frac3{4}) + 377.4833 = 1$$  and

$$ \displaystyle y'_n(-\frac3{4}) = c_1e^{-\frac3{4}} + 2c_2e^{2(-\frac3{4})} + 7(0.0310)(-\frac3{4})^6 + 6(0.3619)(-\frac3{4})^5 + \cdots $$ $$ \displaystyle 5(2.6492)(-\frac3{4})^4 + 4(14.4946)(-\frac3{4})^3 + 3(60.5479)(-\frac3{4})^2 + 2(185.6066)(-\frac3{4}) + 375.3933 = 0 $$

Solving for the constants gives us $$ \displaystyle c_1 = -2.6757 $$ $$ \displaystyle c_2 = -375.1733 $$

Therefore, $$ \displaystyle y_n(x) = -2.6757e^x - 375.1733e^{2x} + 0.0310x^7 + 0.3619x^6 + 2.6492x^5 + 14.4946x^4 + 60.5479x^3 + 185.6066x^2 + 375.3933x + 377.4833 $$ and

n = 11 The particular solution for n = 11 can be obtained from the following: $$ \displaystyle y_p = K_11x^11 + K_10x^10 + K_9x^9 + K_8x^8 + K_7x^7 + K_6x^6 + K_5x^5 + K_4x^4 + K_3x^3 + K_2x^2 + K_1x^1 + K_0. $$ Also, $$ \displaystyle y_p' = 11K_11x^10 + 10K_10x^9 + 9K_9x^8 + 8K_8x^7 + 7K_7x^6 + 6K_6x^5 + 5K_5x^4 + 4K_4x^3 + 3K_3x^2 + 2K_2x + K_1 $$ and $$ \displaystyle y_p'' = 110K_11x^9 + 90K_10x^8 + 72K_9x^7 + 56K_8x^6 + 42K_7x^5 + 30K_6x^4 + 20K_5x^3 + 12K_4x^2 + 6K_3x + 2K_2. $$

Plugging back into the given ODE, and equating to the excitation gives us $$ \displaystyle (110K_11x^9 + 90K_10x^8 + 72K_9x^7 + 56K_8x^6 + 42K_7x^5 + 30K_6x^4 + 20K_5x^3 + 12K_4x^2 + 6K_3x + 2K_2) - 3(11K_11x^10 + \cdots $$ $$ \displaystyle 10K_10x^9 + 9K_9x^8 + 8K_8x^7 + 7K_7x^6 + 6K_6x^5 + 5K_5x^4 + 4K_4x^3 + 3K_3x^2 + 2K_2x + K_1) + 2(K_11x^11 + K_10x^10 + K_9x^9 + K_8x^8 + K_7x^7 + K_6x^6 + K_5x^5 + \cdots $$ $$ \displaystyle K_4x^4 + K_3x^3 + K_2x^2 + K_1x^1 + K_0) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \frac{x^5}{5} - \frac{x^6}{6} + \frac{x^7}{7} - \frac{x^7}{8} + \frac{x^7}{9} - \frac{x^7}{10} + \frac{x^7}{11} $$

Simplified, $$ \displaystyle (110K_11x^9 + 90K_10x^8 + 72K_9x^7 + 56K_8x^6 + 42K_7x^5 + 30K_6x^4 + 20K_5x^3 + 12K_4x^2 + 6K_3x + 2K_2) - \cdots $$ $$ \displaystyle (33K_11x^10 + 30K_10x^9 + 27K_9x^8 + 24K_8x^7 + 21K_7x^6 + 18K_6x^5 + 15K_5x^4 + 12K_4x^3 + 9K_3x^2 + 6K_2x + 3K_1) + \cdots $$ $$ \displaystyle (2K_11x^11 + 2K_10x^10 + 2K_9x^9 + 2K_8x^8 + 2K_7x^7 + 2K_6x^6 + 2K_5x^5 + 2K_4x^4 + 2K_3x^3 + 2K_2x^2 + 2K_1x^1 + 2K_0) = \cdots $$ $$ \displaystyle x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \frac{x^5}{5} - \frac{x^6}{6} + \frac{x^7}{7} - \frac{x^7}{8} + \frac{x^7}{9} - \frac{x^7}{10} + \frac{x^7}{11}$$

Creating a matrix for Matlab to solve for the unknown values of K



Now, we have $$ \displaystyle y_p = 0.0197x^11 + 0.3474x^10 + 4.1499x^9 + 40.4165x^8 + \cdots $$ $$ \displaystyle 335.6321x^7 + 2392.5102x^6 + 20348.2561x^5 + 140399.9629x^4 + 638917.2891x^3 + 2032728.1323x^2 + 4181432.7467x + 4239420.9877 $$

and our final solution is $$ \displaystyle y_n(x) = c_1e^x + c_2e^{2x} + 0.0197x^11 + 0.3474x^10 + 4.1499x^9 + \cdots $$ $$ \displaystyle 40.4165x^8 + 335.6321x^7 + 2392.5102x^6 + 20348.2561x^5 + 140399.9629x^4 + 638917.2891x^3 + 2032728.1323x^2 + 4181432.7467x + 4239420.9877 $$

Evaluating at our initial conditions gives $$ \displaystyle y_n(-\frac3{4}) = c_1e^{-\frac3{4}} + c_2e^{2(-\frac3{4})} + 0.0197(-\frac3{4})^11 + 0.3474(-\frac3{4})^10 + 4.1499(-\frac3{4})^9 + 40.4165(-\frac3{4})^8 + \cdots $$ $$ \displaystyle 335.6321(-\frac3{4})^7 + 2392.5102(-\frac3{4})^6 + 20348.2561(-\frac3{4})^5 + 140399.9629(-\frac3{4})^4 + 638917.2891(-\frac3{4})^3 +  \cdots $$ $$ \displaystyle 2032728.1323(-\frac3{4})^2 + 4181432.7467(-\frac3{4}) + 4239420.9877 = 1 $$   and

$$ \displaystyle y'_n(-\frac3{4}) = c_1e^{-\frac3{4}} + 2c_2e^{2(-\frac3{4})} + 11(0.0197)(-\frac3{4})^10 + 10(0.3474)(-\frac3{4})^9 + \cdots $$ $$ \displaystyle 9(4.1499)(-\frac3{4})^8 + 8(40.4165)(-\frac3{4})^7 + 7(335.6321)(-\frac3{4})^6 + 6(2392.5102)(-\frac3{4})^5 + 5(20348.2561)(-\frac3{4})^4 + \cdots $$ $$ \displaystyle 4(140399.9629)(-\frac3{4})^3 + 3(638917.2891)(-\frac3{4})^2 + 2(2032728.1323)(-\frac3{4}) + 4181432.7467 = 0 $$

Solving for the constants gives us $$ \displaystyle c_1 = -484 $$ $$ \displaystyle c_2 = -1753750 $$

Therefore, $$ \displaystyle y_n(x) = -484e^x - 1753750e^{2x} + 0.0197x^11 + 0.3474x^10 + 4.1499x^9 + 40.4165x^8 + \cdots $$ $$ \displaystyle 335.6321x^7 + 2392.5102x^6 + 20348.2561x^5 + 140399.9629x^4 + 638917.2891x^3 + 2032728.1323x^2 + \cdots $$ $$ \displaystyle 4181432.7467x + 4239420.9877 $$ and 3. The Following Matlab function uses ode45 to calculate and graph alongside the functions previously obtained.