User:Egm4313.s12.team8/R4

=R4.1 - Set up a matrix for solving coefficients for general form of polynomial excitation=

Problem Statement
Set up the matrix A as in (1) p.7-21 for the general case, with the matrix coefficients for rows 1, 2, 3, (n-2), (n-1), and n filled in.

Solution
The general form of (2) p.7b-13 is shown on p.7c-20 and is as follows:
 * $$\sum_{j=0}^{n-2}[c_{j+2} (j+2) (j+1) + a c_{j+1} (j+1) + bc_j]x^j

+ac_nnx^{n-1} + b[c_{n-1}x^{n-1} + c_nx^n] = \sum_{j=0}^{n} d_jx^j $$

When j=0:
 * $$2c_{2}+ac_{1}+bc_{0}=d_{0}$$

When j=1:
 * $$6c_{3}+2ac_{2}+bc_{1}=d_{1}$$

When j=2:
 * $$12c_{4}+3ac_{3}+bc_{2}=d_{2}$$

When j=(n-2):
 * $$[c_{n}(n)(n-1)+ac_{n-1}(n-1)+bc_{n-2}]=d_{n-2}$$

When j=(n-1):
 * $$ac_{n}n+bc_{n-1}=d_{n-1}$$

When j=n:
 * $$bc_{n}=d_{n}$$

Where $$c=[c_0, c_1, ..., c_{n-1}, c_n]^{T}$$ and $$d=[d_0, d_1, ..., d_{n-1}, d_n]^{T}$$

and $$Ac=d$$

The general form of matrix A can be created from the coefficients shown. $$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} $$

=R4.2 - ODE with $$\sin x$$ as its excitation=

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).

=R4.3 - ODE with $$\log (1+x)$$ as its excitation=

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.

=R4.4 - Extend the Accuracy of the Solution Beyond $$\hat x = 0$$=

Problem Statement
Back up away a little from the brink of non-convergence at $$x = 1$$ for the Taylor series of $$\log (1+x)$$ about $$\hat x = 0$$, and consider the point $$x_1 = 0.9$$.

Find the value of $$y_n(x_1)$$, $$y_n'(x_1)$$ that will serve as initial conditions for the next iteration to extend the domain of accuracy of the analytical solution. Find $$n$$ sufficiently high so that $$y_n(x_1)$$ and $$y_n'(x_1)$$ do not differ from the numerical solution by more than $$10^{-5}$$.

Solution
The following MATLAB code generates the numerical solution to the problem:

The following MATLAB function will generate the output, as well as the coefficients, of a series solution to the ODE:

Plotting the absolute error at $$x_1$$ as a function of $$n$$ gives:

The minimum error is thus found at $$n = 15$$ for both $$y_n(x_1)$$ and $$y_n'(x_1)$$ and is roughly:

This is a couple orders of magnitude greater than the desired $$10^{-5}$$. Error increases for $$n > 15$$ due to the truncation error inherent in computing numerical answers.

Therefore, the initial conditions of the next iteration so as to extend the domain of accuracy of the analytical solution are: $$\begin{align} y_{15}(x_1) &= -22.1530 \\ y_{15}'(x_1) &= -55.9732 \end{align}$$

Problem Statement
Develop $$ \displaystyle log(1+x)$$ in a Taylor Series about â=1.

Compute for n= 4, 7, 11.

Plot these three functions along with the real solution.

Find the domain of convergence.

Solution
Taylor Series expansions follow the form:
 * $$ \ \sum_{n = 0}^{\infty} \frac { f^n(a) (x-a)^n }{n!}\ $$

For our problem this translates to:
 * $$ \ \sum_{n = 1}^{\infty} (-1)^{n+1}\frac { (x-1)^n }{n}\ $$

We start the summation at 1 because log(0) is not defined.

For n=4 terms this expands to:
 * $$ (x-1)- \frac {(x-1)^2}{2} + \frac {(x-1)^3}{3} - \frac {(x-1)^4}{4} $$

For n=7 terms this expands to:
 * $$ (x-1)- \frac {(x-1)^2}{2} + \frac {(x-1)^3}{3} - \frac {(x-1)^4}{4} + \frac {(x-1)^5}{5} - \frac {(x-1)^6}{6} + \frac {(x-1)^7}{7}  $$

For n=11 terms this expands to:
 * $$ (x-1)- \frac {(x-1)^2}{2} + \frac {(x-1)^3}{3} - \frac {(x-1)^4}{4} + \frac {(x-1)^5}{5} - \frac {(x-1)^6}{6} + \frac {(x-1)^7}{7} - \frac {(x-1)^8}{8} + \frac {(x-1)^9}{9} - \frac {(x-1)^{10}}{10} + \frac {(x-1)^{11}}{11} $$

Graph
Now these 3 functions will be plotted against the actual solution:

It can then be found from observation of the graph that the domain of convergence is (0,2).

Problem Statement
Find $$\displaystyle y_{n}(x) $$ for n=4,7,11 such that: $$\displaystyle y''_{n}+ay'_{n}+by_{n}=r_{n}(x) $$       (1) for x in [.9,3] with the initial conditions found i.e, $$\displaystyle y_{n}(x_{1}), y'_{n}(x_1). $$ Plot $$\displaystyle y_{n}(x) $$  for n=4,7,11 for x in [.9,3].

Solution
Using a modified version of the Matlab code used in 4.4.1, shown here below, we can solve our coefficients for each y equation (at the specified n values): Our previously solved initial conditions are: $$\displaystyle y_{n}(x_{1})=-22.153,y'_{n}(x_{1})=-55.9732 $$ Using the above code, we can solve for the coefficients and final y equation to be as shown below: For n=4: $$\displaystyle y_n(x) = 8.9210e^x - 5.6353e^{2x} -0.125x^4 - 0.583x^3 -2.125x^2 - 4.125x^1 - 4.0625 $$     (4.4.3.1) For n=7: $$ \displaystyle y_n(x) = -615.0725e^x - 3.3884e^{2x} + 0.07143x^7 + 0.6666x^6 + 4.6x^5 + 24.375x^4 + 100.4166x^3 + 305.375x^2 + 615.375x + 617.6875 $$    (4.4.3.2) For n=11: $$ \displaystyle y_n(x) = -3301815e^x + 734.893e^{2x} + 0.04545x^{11} + 0.7x^{10} + 8.0556x^9 + \cdots $$ $$ \displaystyle 77.1875x^8 + 636.3214x^7 + 4520x^6 + 27318x^5 + 137082x^4 + 549316x^3 + 1649429x^2 + 3300389x + 3301079 $$    (4.4.3.3)

Problem Statement
Use the matlab command ode45 to integrate numerically using the initial conditions over x in [0.9, 3] and obtain the numerical solution $$y(x)$$. Plot $$y(x)$$ in the same figure as the above $$y_n(x)$$.

Solution
The following MATLAB code using the function coeffs defined above in R4.4.3 obtains us the following graph:

=Team Contributions=