User:Egm4313.s12.team11.sheider/R4.2a: Lecture 7 p.7-26 pb. 1-2

Problem Statement
Given: $$ y^{''} - 3y^{'} +2y = sin(x)\!$$

With initial conditions: $$ y(0) = 1, y'(0) = 0 \!$$

Using the Taylor series for sin(x), reproduce the graph in the lecture notes p.7-24.

Solution
The Taylor series expansion for sin(x) that is plotted with n = 13 is as follows:

$$ y = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!} - \frac{x^{11}}{11!} + \frac{x^{13}}{13!} - \frac{x^{15}}{15!} + \frac{x^{17}}{17!} - \frac{x^{19}}{19!} + \frac{x^{21}}{21!} - \frac{x^{23}}{23!} + \frac{x^{25}}{25!} \!$$

Using MatLab, the following Taylor series expansion was plotted and coded:



The plot created with n = 13 (i.e. 13 terms) is as follows:



Problem Statement
Given: $$ y^{''} - 3y^{'} +2y = r(x)\!$$

With initial conditions: $$ y(0) = 1, y'(0) = 0 \!$$

Letting $$ r(x) \!$$ equal the truncated Taylor series of $$ sin(x) \!$$, i.e. $$ r(x) = \sum_{k=0}^{n} \frac{(-1)^kt^{2k+1}}{(2k+1)!} \!$$

Find the overall solution $$ y_{n}(x) \!$$ for $$ n = 3,5,9 \!$$ and plot these solutions on the interval from $$ [0,4\pi ] \!$$

Solution
First finding the homogenous solution to the ODE:

The characteristic equation:

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

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

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

And the homogenous solution is:

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

Next the particular solution will be evaluated.

For n = 3:

The excitation is therefore: $$ r_{x} = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!}\!$$

Therefore the particular solution has a form:

$$ y_{p} = K_{7}x^{7} + K_{6}x^{6} + K_{5}x^{5} + K_{4}x^{4} + K_{3}x^{3} + K_{2}x^{2} + K_{1}x + K_{0} \!$$

Differentiating:

$$ y_{p}^{'} = 7K_{7}x^{6} + 6K_{6}x^{5} + 5K_{5}x^{4} + 4K_{4}x^{3} + 3K_{3}x^{2} + 2K_{2}x + 1K_{1} \!$$

$$ y_{p}^{''} = 42K_{7}x^{5} + 30K_{6}x^{4} + 20K_{5}x^{3} + 12K_{4}x^{2} + 6K_{3}x + 2K_{2} \!$$

Plugging these values into the ODE and equating them to the excitation:

$$ 42K_{7}x^{5} + 30K_{6}x^{4} + 20K_{5}x^{3} + 12K_{4}x^{2} + 6K_{3}x + 2K_{2} \!$$

$$ - 3(7K_{7}x^{6} + 6K_{6}x^{5} + 5K_{5}x^{4} + 4K_{4}x^{3} + 3K_{3}x^{2} + 2K_{2}x + 1K_{1})\!$$

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

$$ 42K_{7}x^{5} + 30K_{6}x^{4} + 20K_{5}x^{3} + 12K_{4}x^{2} + 6K_{3}x + 2K_{2} \!$$

$$ - 21K_{7}x^{6} -18K_{6}x^{5} -15K_{5}x^{4} -12K_{4}x^{3} -9K_{3}x^{2} -6K_{2}x -3K_{1}\!$$

$$ + 2K_{7}x^{7} + 2K_{6}x^{6} + 2K_{5}x^{5} + 2K_{4}x^{4} + 2K_{3}x^{3} + 2K_{2}x^{2} + 2K_{1}x + 2K_{0} = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} \!$$

To solve this, we will use an upper triangular matrix, and solve using Matlab. The matrix is as follows:

$$ \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 \\ 0 \\ -\frac{1}{3!} \\ 0 \\ \frac{1}{5!} \\ 0 \\ -\frac{1}{7!} \end{bmatrix}\!$$

The answer is calculated in Matlab:



Therefore: $$ y_{p} = \frac{-1}{10080}x^{7} + \frac{-1}{960}x^{6} + \frac{-1}{320}x^{5} + \frac{-1}{128}x^{4} + \frac{-19}{192}x^{3} + \frac{-51}{128}x^{2} + \frac{-51}{128}x + \frac{-51}{256} \!$$

The final solution is then found to be: $$ y_{n} = c_{1}e^{x} + c_{2}e^{2x} + \frac{-1}{10080}x^{7} + \frac{-1}{960}x^{6} + \frac{-1}{320}x^{5} + \frac{-1}{128}x^{4} + \frac{-19}{192}x^{3} + \frac{-51}{128}x^{2} + \frac{-51}{128}x + \frac{-51}{256} \!$$

Evaluating at the initial conditions, we have:

$$ y_{n}(0) = c_{1} + c_{2} + \frac{-51}{256} = 1 \!$$

$$ y_{n}^{'}(0) = c_{1} + 2c_{2} + \frac{-51}{128} = 0\!$$

Solving this system of equations, we find:

$$ c_{1} = 2, c_{2} = \frac{-205}{256} \!$$

Therefore the final solution is:

$$ y_{n} = 2e^{x} + \frac{-205}{256}e^{2x} + \frac{-1}{10080}x^{7} + \frac{-1}{960}x^{6} + \frac{-1}{320}x^{5} + \frac{-1}{128}x^{4} + \frac{-19}{192}x^{3} + \frac{-51}{128}x^{2} + \frac{-51}{128}x + \frac{-51}{256} \!$$

Plotting this equation in Matlab yields:



For n = 5:

The excitation is therefore: $$ r_{x} = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!} - \frac{x^{11}}{11!}\!$$

Therefore the particular solution has a form:

$$ y_{p} = K_{11}x^{11} + K_{10}x^{10}+ K_{9}x^{9} + K_{8}x^{8} + K_{7}x^{7}+ K_{6}x^{6} + K_{5}x^{5} + K_{4}x^{4} + K_{3}x^{3} + K_{2}x^{2} + K_{1}x + K_{0} \!$$

Differentiating:

$$ y_{p}^{'} = 11K_{11}x^{10} + 10K_{10}x^{9}+ 9K_{9}x^{8} + 8K_{8}x^{7}+ 7K_{7}x^{6} + 6K_{6}x^{5} + 5K_{5}x^{4} + 4K_{4}x^{3} + 3K_{3}x^{2} + 2K_{2}x + 1K_{1} \!$$

$$ y_{p}^{''} = 110K_{11}x^{9} + 90K_{10}x^{8}+ 72K_{9}x^{7} + 56K_{8}x^{6}+ 42K_{7}x^{5} + 30K_{6}x^{4} + 20K_{5}x^{3} + 12K_{4}x^{2} + 6K_{3}x + 2K_{2} \!$$

Plugging these values into the ODE and equating them to the excitation, and then solving them by using a upper triangular matrix as before (just as in the n=3 example) in Matlab:



Therefore: $$ y_{p} = \frac{-1}{79833600}x^{11} + \frac{-1}{4838400}x^{10} + \frac{-1}{967680}x^{9} + \frac{-1}{215040}x^{8} + \frac{-7}{59419}x^{7} + \frac{-17}{15360}x^{6} \!$$

$$ + \frac{-17}{5120}x^5 + \frac{-17}{2048}x^4 + \frac{-307}{3072}x^3 + \frac{-819}{2048}x^2 + \frac{-819}{2048}x + \frac{-819}{4096} \!$$

The final solution is then found to be: $$ y_{n} = c_{1}e^{x} + c_{2}e^{2x} + \frac{-1}{79833600}x^{11} + \frac{-1}{4838400}x^{10} + \frac{-1}{967680}x^{9} + \frac{-1}{215040}x^{8} + \frac{-7}{59419}x^{7} + \frac{-17}{15360}x^{6} \!$$

$$ + \frac{-17}{5120}x^5 + \frac{-17}{2048}x^4 + \frac{-307}{3072}x^3 + \frac{-819}{2048}x^2 + \frac{-819}{2048}x + \frac{-819}{4096} \!$$

Evaluating at the initial conditions, we have:

$$ y_{n}(0) = c_{1} + c_{2} + \frac{-819}{4096} = 1 \!$$

$$ y_{n}^{'}(0) = c_{1} + 2c_{2} + \frac{-819}{2048} = 0\!$$

Solving this system of equations, we find:

$$ c_{1} = 2, c_{2} = \frac{-3277}{4096} \!$$

Therefore the final solution is:

$$ y_{n} = 2e^{x} + \frac{-3277}{4096}e^{2x} + \frac{-1}{79833600}x^{11} + \frac{-1}{4838400}x^{10} + \frac{-1}{967680}x^{9} + \frac{-1}{215040}x^{8} + \frac{-7}{59419}x^{7} + \frac{-17}{15360}x^{6} \!$$

$$ + \frac{-17}{5120}x^5 + \frac{-17}{2048}x^4 + \frac{-307}{3072}x^3 + \frac{-819}{2048}x^2 + \frac{-819}{2048}x + \frac{-819}{4096} \!$$ Plotting this equation in Matlab yields:



For n = 9:

The excitation is therefore: $$ r_{x} = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!} - \frac{x^{11}}{11!} + \frac{x^{13}}{13!} - \frac{x^{15}}{15!} + \frac{x^{17}}{17!} - \frac{x^{19}}{19!}\!$$

Therefore the particular solution has a form:

$$ y_{p} = K_{19}x^{19}+ K_{18}x^{18} + K_{17}x^{17} + K_{16}x^{16} + K_{15}x^{15} + K_{14}x^{14} + K_{13}x^{13} + K_{12}x^{12} + K_{11}x^{11} + K_{10}x^{10} \!$$

$$ + K_{9}x^{9} + K_{8}x^{8} + K_{7}x^{7}+ K_{6}x^{6} + K_{5}x^{5} + K_{4}x^{4} + K_{3}x^{3} + K_{2}x^{2} + K_{1}x + K_{0} \!$$

Differentiating:

$$ y_{p}^{'} = 19K_{19}x^{18}+ 18K_{18}x^{17} + 17K_{17}x^{16} + 16K_{16}x^{15} + 15K_{15}x^{14} + 14K_{14}x^{13} + 13K_{13}x^{12} + 12K_{12}x^{11} + 11K_{11}x^{10} + 10K_{10}x^{9} \!$$

$$ + 9K_{9}x^{8} + 8K_{8}x^{7}+ 7K_{7}x^{6} + 6K_{6}x^{5} + 5K_{5}x^{4} + 4K_{4}x^{3} + 3K_{3}x^{2} + 2K_{2}x + 1K_{1} \!$$

$$ y_{p}^{''} = 342K_{19}x^{17}+ 306K_{18}x^{16} + 272K_{17}x^{15} + 240K_{16}x^{14} + 210K_{15}x^{13} + 182K_{14}x^{12} + 156K_{13}x^{11} + 132K_{12}x^{10} + 110K_{11}x^{9} + 90K_{10}x^{8} \!$$

$$ +72K_{9}x^{7} + 56K_{8}x^{6}+ 42K_{7}x^{5} + 30K_{6}x^{4} + 20K_{5}x^{3} + 12K_{4}x^{2} + 6K_{3}x + 2K_{2} \!$$

Plugging these values into the ODE and equating them to the excitation, and then solving them by using an upper triangular matrix as before (just as in the n=3 example) in Matlab:



Therefore: $$ y_{p} = \frac{-1}{2.433E17}x^{19} + \frac{-1}{8.536E15}x^{18} + \frac{-1}{9.485E14}x^{17} + \frac{-1}{1.112E14}x^{16} + \frac{-1}{2.202E12}x^{15} + \frac{-1}{1.094E11}x^{14} \!$$

$$ + \frac{-1}{1.563E10}x^{13} + \frac{-1}{2.404E9}x^{12} + \frac{-1}{6.657E7}x^{11} + \frac{-1}{4.537E6}x^{10} + \frac{-1}{9.074E5}x^9 + \frac{-4}{8.066E5}x^8 + \frac{-38}{3.192E5}x^7 \!$$

$$ + \frac{-73}{657010}x^{6} + \frac{-218}{65401}x^{5} + \frac{-218}{65401}x^{4} + \frac{-3441}{49157}x^{3} + \frac{-1198}{4061}x^2 + \frac{-1431}{8177}x + \frac{145}{4462} \!$$

The final solution is then found to be: $$ y_{n} = c_{1}e^{x} + c_{2}e^{2x} + \frac{-1}{2.433E17}x^{19} + \frac{-1}{8.536E15}x^{18} + \frac{-1}{9.485E14}x^{17} + \frac{-1}{1.112E14}x^{16} + \frac{-1}{2.202E12}x^{15} + \frac{-1}{1.094E11}x^{14} \!$$

$$ + \frac{-1}{1.563E10}x^{13} + \frac{-1}{2.404E9}x^{12} + \frac{-1}{6.657E7}x^{11} + \frac{-1}{4.537E6}x^{10} + \frac{-1}{9.074E5}x^9 + \frac{-4}{8.066E5}x^8 + \frac{-38}{3.192E5}x^7 \!$$

$$ + \frac{-73}{657010}x^{6} + \frac{-218}{65401}x^{5} + \frac{-218}{65401}x^{4} + \frac{-3441}{49157}x^{3} + \frac{-1198}{4061}x^2 + \frac{-1431}{8177}x + \frac{145}{4462} \!$$

Evaluating at the initial conditions, we have:

$$ y_{n}(0) = c_{1} + c_{2} + \frac{145}{4462} = 1 \!$$

$$ y_{n}^{'}(0) = c_{1} + 2c_{2} + \frac{-1431}{8177} = 0\!$$

Solving this system of equations, we find:

$$ c_{1} = 1.76, c_{2} = -0.7925 \!$$

Therefore the final solution is:

$$ y_{n} = 1.76e^{x} + -0.7925e^{2x} + \frac{-1}{2.433E17}x^{19} + \frac{-1}{8.536E15}x^{18} + \frac{-1}{9.485E14}x^{17} + \frac{-1}{1.112E14}x^{16} + \frac{-1}{2.202E12}x^{15} + \frac{-1}{1.094E11}x^{14} \!$$

$$ + \frac{-1}{1.563E10}x^{13} + \frac{-1}{2.404E9}x^{12} + \frac{-1}{6.657E7}x^{11} + \frac{-1}{4.537E6}x^{10} + \frac{-1}{9.074E5}x^9 + \frac{-4}{8.066E5}x^8 + \frac{-38}{3.192E5}x^7 \!$$

$$ + \frac{-73}{657010}x^{6} + \frac{-218}{65401}x^{5} + \frac{-218}{65401}x^{4} + \frac{-3441}{49157}x^{3} + \frac{-1198}{4061}x^2 + \frac{-1431}{8177}x + \frac{145}{4462} \!$$

Plotting this equation in Matlab yields:



Note: On the interval from $$ 0 \!$$ to $$ 4\pi\!$$, the resulting plots of the solutions, on such a large scale (note that the Y-axis is forced to be on the order of $$ 10^{10}\!$$!) each plot looks almost exactly identical. It is not until you are able to zoom in a lot do you see the very slight change in the curve of each plot on this interval.