User:Egm4313.s12.team8.lucas/R4.2

=R4.2=

Problem Statement
Consider the L2-ODE-CC with sinx as its excitation.

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

Initial Conditions:

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

Part 1) Use the Taylor series for sinx to reproduce the figure on p. 7-24 in lecture notes.

Part 2) Find the overall solution to the L2-ODE-CC above by substituting the Taylor series approximations for sinx at n=3,5, and 9 for the excitation equation. Plot the solutions over the interval $$\ [0,4 \pi]$$.

Part 3) Find the exact overall solution to the L2-ODE-CC above by using the function sinx as the excitation equation. Plot the solution and compare it to the solutions from Part 2.

Part 1
The Taylor series expansion of sinx takes the form:

$$\ sinx=\sum_{j=0}^{k}\frac{{}(-1)^{j}x^{2j+1}}{(2j+1)!}$$

Expanding this summation for j=6 gives:

$$\ sinx=\frac{x}{1!}-\frac{x^{3}}{3!}+\frac{x^{5}}{5!}-\frac{x^{7}}{7!}+\frac{x^{9}}{9!}-\frac{x^{11}}{11!}+\frac{x^{13}}{13!}$$

$$\ sinx=x-\frac{x^{3}}{6}+\frac{x^{5}}{120}-\frac{x^{7}}{5040}+\frac{x^{9}}{362880}-\frac{x^{11}}{39916800}+\frac{x^{13}}{6227020800}$$

By seperating and graphing each of the terms, we can see how the sum of the polynomials equal the sin function.




 * The value for n in the plot is equal to 2j+1, not the number of terms in the series.

Part 2
To find the general solution to the ODE, we first must find the homogeneous solution:

$$\ y''-3y'+2y=0$$

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

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

$$\ \lambda_{1}-1=0  =>  \lambda_{1}=1$$

$$\ \lambda_{2}-2=0  =>  \lambda_{2}=2$$

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

n=3
Because n=3, the excitation equation approximating sinx becomes:

$$\ r(x)=x-\frac{x^{3}}{3!}$$

The general form of $$\ y_p$$ for a polynomial excitation equation is a polynomial with the same highest degree.

$$\ y_{p}(x)=Ax^3+Bx^2+Cx+D$$

Differentiating $$\ y_p$$ and its derivative gives:

$$\ y'_{p}(x)=3Ax^2+2Bx+C$$

$$\ y''_{p}(x)=6Ax+2B$$

By substituting these equations into the original ODE we get:

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

$$\ [6Ax+2B]-3[3Ax^2+2Bx+C]+2[Ax^3+Bx^2+Cx+D]=x-\frac{x^{3}}{3!}$$

Combining like terms gives:

$$\ 2Ax^3+(2B-9A)x^2+(6A-6B+2C)x+(2B-3C+2D)=x-\frac{x^{3}}{3!}$$

Equating like terms gives:

$$\ 2Ax^3=-\frac{x^{3}}{3!}   =>   A=-\frac{1}{12}$$

$$\ (2B-9A)x^2=0      =>     B=-\frac{3}{8}$$

$$\ (6A-6B+2C)x=x         =>      C=-\frac{3}{8}$$

$$\ (2B-3C+2D)=0         =>    D=-\frac{1}{16}$$

So the particular solution becomes:

$$\ y_{p}(x)=-\frac{1}{12}x^3-\frac{3}{8}x^2-\frac{3}{8}x-\frac{1}{16}$$

The general solution is the sum of the homogeneous and particular soluions:

$$\ y(x)=c_{1}e^x+c_{2}e^{2x}-\frac{1}{12}x^3-\frac{3}{8}x^2-\frac{3}{8}x-\frac{1}{16}$$

Differentiating gives:

$$\ y'(x)=c_{1}e^x+2c_{2}e^{2x}-\frac{1}{4}x^3-\frac{3}{4}x^2-\frac{3}{8}$$

Applying initial conditions gives:

$$\ y(0)=1=c_{1}+c_{2}-\frac{1}{16}$$

$$\ y'(0)=0=c_{1}+2c_{2}-\frac{3}{8}$$

Solving the system of equations gives:

$$\ c_{1}=2$$

$$\ c_{2}=-\frac{13}{16}$$

The final approximated solution for n=3 is:

$$\ y(x)=2e^x-\frac{13}{16}e^{2x}-\frac{1}{12}x^3-\frac{3}{8}x^2-\frac{3}{8}x-\frac{1}{16}$$

n=5
Because n=5, the excitation equation approximating sinx becomes:

$$\ r(x)=x-\frac{x^{3}}{3!}+\frac{x^{5}}{5!}$$

The general form of $$\ y_p$$ for a polynomial excitation equation is a polynomial with the same highest degree.

$$\ y_{p}(x)=Ax^5+Bx^4+Cx^3+Dx^2+Ex+F$$

Differentiating $$\ y_p$$ and its derivative gives:

$$\ y'_{p}(x)=5Ax^4+4Bx^3+3Cx^2+2Dx+E$$

$$\ y''_{p}(x)=20Ax^3+12Bx^2+6Cx+2D$$

By substituting these equations into the original ODE we get:

$$\ y''-3y'+2y=r(x)=x-\frac{x^{3}}{3!}+\frac{x^{5}}{5!}$$

$$\ [20Ax^3+12Bx^2+6Cx+2D]-3[5Ax^4+4Bx^3+3Cx^2+2Dx+E]+2[Ax^5+Bx^4+Cx^3+Dx^2+Ex+F]=x-\frac{x^{3}}{3!}+\frac{x^{5}}{5!}$$

Combining like terms gives:

$$\ 2Ax^5+(2B-15A)x^4+(2C-12B+20A)x^3+(2D-9C+12B)x^2+(2E-6D+6C)x+(2F-3E+2D)=x-\frac{x^{3}}{3!}+\frac{x^{5}}{5!}$$

Equating like terms gives:

$$\ 2Ax^5=\frac{x^{5}}{5!}   =>   A=\frac{1}{240}$$

$$\ (2B-15A)x^4=0      =>     B=\frac{1}{32}$$

$$\ (2C-12B+20A)x^3=-\frac{x^{3}}{3!}    =>      C=\frac{1}{16}$$

$$\ (2D-9C+12B)x^2=0         =>    D=\frac{3}{32}$$

$$\ (2E-6D+6C)x=x       =>      E=\frac{19}{32}$$

$$\ (2F-3E+2D)=0       =>       F=\frac{51}{64}$$

So the particular solution becomes:

$$\ y_{p}(x)=\frac{1}{240}x^5+\frac{1}{32}x^4+\frac{1}{16}x^3+\frac{3}{32}x^2+\frac{19}{32}x+\frac{51}{64}$$

The general solution is the sum of the homogeneous and particular soluions:

$$\ y(x)=c_{1}e^x+c_{2}e^{2x}+\frac{1}{240}x^5+\frac{1}{32}x^4+\frac{1}{16}x^3+\frac{3}{32}x^2+\frac{19}{32}x+\frac{51}{64}$$

Differentiating gives:

$$\ y'(x)=c_{1}e^x+2c_{2}e^{2x}+\frac{1}{48}x^4+\frac{1}{8}x^3+\frac{3}{16}x^2+\frac{3}{16}x+\frac{19}{32}$$

Applying initial conditions gives:

$$\ y(0)=1=c_{1}+c_{2}+\frac{51}{64}$$

$$\ y'(0)=0=c_{1}+2c_{2}+\frac{19}{32}$$

Solving the system of equations gives:

$$\ c_{1}=1$$

$$\ c_{2}=-\frac{51}{64}$$

The final approximated solution for n=5 is:

$$\ y(x)=2e^x-\frac{51}{64}e^{2x}+\frac{1}{240}x^5+\frac{1}{32}x^4+\frac{1}{16}x^3+\frac{3}{32}x^2+\frac{19}{32}x+\frac{51}{64}$$

n=9
Because n=9, the excitation equation approximating sinx becomes:

$$\ r(x)=x-\frac{x^{3}}{3!}+\frac{x^{5}}{5!}-\frac{x^{7}}{7!}+\frac{x^{9}}{9!}$$

The general form of $$\ y_p$$ for a polynomial excitation equation is a polynomial with the same highest degree.

$$\ y_{p}(x)=Ax^9+Bx^8+Cx^7+Dx^6+Ex^5+Fx^4+Gx^3+Hx^2+Jx+K$$

Differentiating $$\ y_p$$ and its derivative gives:

$$\ y'_{p}(x)=9Ax^8+8Bx^7+7Cx^6+6Dx^5+5Ex^4+4Fx^3+3Gx^2+2Hx+J$$

$$\ y''_{p}(x)=72Ax^7+63Bx^6+42Cx^5+30Dx^4+20Ex^3+Fx^2+6Gx+2H$$

By substituting these equations into the original ODE we get:

$$\ y''-3y'+2y=r(x)=x-\frac{x^{3}}{3!}+\frac{x^{5}}{5!}-\frac{x^{7}}{7!}+\frac{x^{9}}{9!}$$

$$\ [72Ax^7+63Bx^6+42Cx^5+30Dx^4+20Ex^3+Fx^2+6Gx+2H]-3[9Ax^8+8Bx^7+7Cx^6+6Dx^5+5Ex^4+4Fx^3+3Gx^2+2Hx+J]+2[Ax^9+Bx^8+Cx^7+Dx^6+Ex^5+Fx^4+Gx^3+Hx^2+Jx+K]=x-\frac{x^{3}}{3!}+\frac{x^{5}}{5!}-\frac{x^{7}}{7!}+\frac{x^{9}}{9!}$$

Combining like terms gives:

$$\ 2Ax^9+(2B-27A)x^8+(2C-24B+72A)x^7+(2D-21C+63B)x^6+(2E-18D+42C)x^5+(2F-15E+30D)x^4+(2G-12F+20E)x^3+(2H-9G+12F)x^2+(2J-6H+6G)x+(2K-3J+2H)=x-\frac{x^{3}}{3!}+\frac{x^{5}}{5!}-\frac{x^{7}}{7!}+\frac{x^{9}}{9!}$$

Equating like terms gives:

$$\ 2Ax^9=\frac{x^{9}}{9!}   =>   A=\frac{1}{725760}$$

$$\ (2B-27A)x^8=0      =>     B=\frac{1}{53760}$$

$$\ (2C-24B+72A)x^7=-\frac{x^{7}}{7!}    =>      C=\frac{1}{13440}$$

$$\ (2D-21C+63B)x^6=0         =>    D=\frac{1}{3840}$$

$$\ (2E-18D+42C)x^5=\frac{x^{5}}{5!}     =>    E=\frac{19}{3840}$$

$$\ (2F-15E+30D)x^4=0        =>       F=\frac{17}{512}$$

$$\ (2G-12F+20E)x^3=-\frac{x^{3}}{3!}     =>      G=\frac{17}{256}$$

$$\ (2H-9G+12F)x^2=0           =>         H=\frac{51}{512}$$

$$\ (2J-6H+6G)x=x          =>       J=\frac{307}{512}$$

$$\ (2K-3J+2H)=0             =>     K=\frac{819}{1024}$$

So the particular solution becomes:

$$\ y_{p}(x)=\frac{1}{725760}x^9+\frac{1}{53760}x^8+\frac{1}{13440}x^7+\frac{1}{3840}x^6+\frac{19}{3840}x^5+\frac{17}{512}x^4+\frac{17}{256}x^3+\frac{51}{512}x^2+\frac{307}{512}x+\frac{819}{1024}$$

The general solution is the sum of the homogeneous and particular soluions:

$$\ y(x)=c_{1}e^x+c_{2}e^{2x}+\frac{1}{725760}x^9+\frac{1}{53760}x^8+\frac{1}{13440}x^7+\frac{1}{3840}x^6+\frac{19}{3840}x^5+\frac{17}{512}x^4+\frac{17}{256}x^3+\frac{51}{512}x^2+\frac{307}{512}x+\frac{819}{1024}$$

Differentiating gives:

$$\ y'(x)=c_{1}e^x+2c_{2}e^{2x}+\frac{1}{80640}x^8+\frac{1}{6720}x^7+\frac{1}{1920}x^6+\frac{1}{640}x^5+\frac{19}{640}x^4+\frac{17}{128}x^3+\frac{51}{256}x^2+\frac{51}{256}x^2+\frac{307}{512}$$

Applying initial conditions gives:

$$\ y(0)=1=c_{1}+c_{2}+\frac{819}{1024}$$

$$\ y'(0)=0=c_{1}+2c_{2}+\frac{307}{512}$$

Solving the system of equations gives:

$$\ c_{1}=1$$

$$\ c_{2}=-\frac{819}{1024}$$

The final approximated solution for n=9 is:

$$\ y(x)=e^x-\frac{819}{1024}e^{2x}+\frac{1}{725760}x^9+\frac{1}{53760}x^8+\frac{1}{13440}x^7+\frac{1}{3840}x^6+\frac{19}{3840}x^5+\frac{17}{512}x^4+\frac{17}{256}x^3+\frac{51}{512}x^2+\frac{307}{512}x+\frac{819}{1024}$$



This image is an unzoomed graph of the three general solutions to the L2-ODE-CC above on the interval $$\ [0,4 \pi]$$.



This image is a zoomed picture of the left side of the graph above. Without zooming, it is impossible to tell the differences, whereas the differences are obvious here.



This image is a zoomed picture of the right side of the graph above. In this graph, the three solutions are labeled by their power. (n=3,5,9)

Part 3
In finding the exact overall solution, we no longer use Taylor series approximations. Instead we use sinx as the excitation and solve accordingly.

$$\ y''-3y'+2y=sinx$$

Our choice for $$\ y_{p}$$ is based on r(x) and can be found in K 2011 p.82 Table 2.1.

$$\ y_{p}(x)=Asinx+Bcosx$$

Differentiating $$\ y_{p}(x)$$ and its derviate yields:

$$\ y'_{p}(x)=-Bsinx+Acosx$$

$$\ y''_{p}(x)=-Asinx-Bcosx$$

Then we substitute the derivatives into the ODE:

$$\ [-Asinx-Bcosx]-3[-Bsinx+Acosx]+2[Asinx+Bcosx]=sinx$$

Combining like terms:

$$\ (3B+A)sinx+(B-3A)cosx=sinx$$

Equating like terms:

$$\ (3B+A)sinx=sinx  => 3B+A=1$$

$$\ (B-3A)cosx=0     => B-3A=0$$

Solving the system of equations gives:

A=0.1 B=0.3

$$\ y_{p}(x)=\frac{1}{10}sinx+\frac{3}{10}cosx$$

The general solution becomes:

$$\ y(x)=y_{h}(x)+y_{p}(x)=c_{1}e^x+c_{2}e^{2x}+\frac{1}{10}sinx+\frac{3}{10}cosx$$

Differentiating the general solution:

$$\ y'(x)=c_{1}e^x+2c_{2}e^{2x}+\frac{1}{10}cosx-\frac{3}{10}sinx$$

Apply initial conditions:

$$\ y(0)=c_{1}e^{0}+c_{2}e^{0}+\frac{1}{10}sin0+\frac{3}{10}cos0=c_{1}+c_{2}+\frac{3}{10}=1 =>  c_{1}+c_{2}=\frac{7}{10}$$

$$\ y'(0)=c_{1}e^{0}+2c_{2}e^{0}+\frac{1}{10}cos0-\frac{3}{10}sin0=0 => c_{1}+2c_{2}=-\frac{1}{10}$$

Solving the system of equatiions:

$$\ c_{1}=1.5$$

$$\ c_{2}=-\frac{8}{10}$$

The final, exact, general solution is:

$$\ y(x)=1.5e^x-\frac{8}{10}e^{2x}+\frac{1}{10}sinx+\frac{3}{10}cosx$$



This image shows the unzoomed graph of all three approximations and the exact solution to the L2-ODE-CC on the interval $$\ [0,4 \pi]$$. However, it is hard to distinguish the graphs without zooming in.

This image is a zoomed part of the graph above. The n=9 solution (green) is much more accurate than the n=5 solution (blue) and the n=3 solution (red) as it is closer to the exact solution (magenta).