Tutorial file 4. MA530. Series Solutions

Examples in this file correspond to O'Neil "Advanced Engineering Mathematics" 6th ed.
	Compare the analytical solutions in the book  with the computer solutions in this file:

Analitic functions

Definition: 
		A function f is analitic at (Subscript[x, 0]) if f(x) has a power series representation in some open interval about (Subscript[x, 0]):
		
		f(x)=\(TraditionalForm\`∑\+\(n = 0\)\%∞\(\( a\_n\)(x - x\_0)\)\^n\)
		
		in some interval .((Subscript[x, 0]) - h, (Subscript[x, 0]) + h)
	
	In Mathematica power series expasion for f about (Subscript[x, 0]) can be caluculated using the operator  Series[f, {x, (Subscript["x", 0]), n}]

Series expansions of some common analitic functions

Series[Exp[x], {x, 0, 10}]

Series[Sin[x], {x, 0, 10}]

Series[Cos[x], {x, 0, 10}]

Series[Log[x], {x, 3, 10}]

Series[Sin[x], {x, 3, 10}]

The same series but evaluated numerically

N[%]

Here is what happens when function is not analitic about (Subscript[x, 0]) :

Series[Log[x], {x, 0, 10}]

Example 4.1 (p.157)            y'+(e^x) y = (x^2);    y(0) = 4

Consider the following initial value problem:
		
		y'+(e^x) y = (x^2);    y(0) = 4
		
		 the theorem 4.1  guarantees an analytic solution at 0.

First solution.

Let us introduce the following function:

F[x_] := y'[x] + Exp[x] y[x] - x^2

The first coefficient is given by the initial condition:

a0 = 4

From the differential equation using the given initial condition we found the first coefficient of the Maclaurin expansion:

F[0] == 0

% /. y[0] -> a0

Solve[%, y'[0]]

a1 = y'[0] /. %[[1]]

Differentiation of F  gives us the second coefficient of the Maclaurin expansion:

F1[x_] = D[F[x], x]

F1[0] == 0

% /. {y[0] -> a0, y'[0] -> a1}

Solve[%, y''[0]]

a2 = y''[0] /. %[[1]]

The second differentiation of F  gives us the third coefficient of the Maclaurin expansion:

F2[x_] = D[F[x], {x, 2}]

F2[0] == 0

% /. {y[0] -> a0, y'[0] -> a1, y''[0] -> 
          a2}

Solve[%,Derivative[3][y][0]]

a3=Derivative[3][y][0]/.%[[1]]

We can do as many steps as we want, but let us find just one more coefficient :

F3[x_] = D[F[x], {x, 3}]

F3[0] == 0

%/.{y[0] -> a0,y'[0] -> a1,y''[0] -> a2,Derivative[3][y][0]->a3}

Solve[%,Derivative[4][y][0]]

a4=Derivative[4][y][0]/.%[[1]]

Now we can write the first four terms of the series solution:

y[x_] = 
      a0 + a1*x + (a2/2!)*x^2 + (a3/3!)*x^3 + (a4/4!)*
          x^4 + O[x]^5

Remove["a*"]

Second solution.

First let us make up a series which coefficients we have to determine, let us consider the first 10 coefficients:

ser = Sum[a[n] x^n, {n, 0, 10}] + O[x]^10

Then we substitute this series into the differential equation:

difeq =  D[ser,x] +Exp[x]*ser == x^2

Coef = LogicalExpand[ difeq  ]

The initial value condition and the first equation in the last expression give us immediately values of the a[0] and a[1]:

a[0] = 4;
a[1] = -4;

Now we can solve for all other cefficients:

coeffs = Solve[Coef, Table[a[i], {i,2,9}]]

Finally let us write down the answer:

y = ser /. coeffs

Compare this answer with the one given in the textbook (p. 158) to see that there is a typo in the textbook, find this typo..

Remove["a*"]

Example 4.3 (p.158)            y''-xy'+(e^x) y = 4;    y(0) = 1,  y' (0) = 4

Consider the following initial value problem:
		
		y''-xy'+(e^x) y = 
        4;    y(0) = 1 y' (0) = 4
		
		 Since -x, (e^x) and 4 are  analytic  at 0, the problems has a series solution expanded about 0

First solution.

Let us introduce the following function:

F[x_] := y''[x] - x*y'[x] + Exp[x] y[x] - 4

The first two coefficients are given by the initial conditions:

a0 = 1;

a1 = 4;

From the differential equation using the given initial condition we found the third coefficient of the Maclaurin expansion:

F[0] == 0

% /. {y[0] -> a0, y'[0] -> a1}

Solve[%, y''[0]]

a2 = y''[0] /. %[[1]]

Let us differentiate F(x) to find the next coefficient of the Maclaurin expansion:

F1[x_] = D[F[x], x]

F1[0] == 0

% /. {y[0] -> a0, y'[0] -> a1, y''[0] -> 
          a2}

Solve[%,Derivative[3][y][0]]

a3=Derivative[3][y][0]/.%[[1]]

The second differentiation of F  gives us the third coefficient of the Maclaurin expansion:

F2[x_] = D[F[x], {x, 2}]

F2[0] == 0

%/.{y[0] -> a0,y'[0] -> a1,y''[0] -> a2,Derivative[3][y][0]->a3}

Solve[%,Derivative[4][y][0]]

a4=Derivative[4][y][0]/.%[[1]]

Now we can write the first five terms of the series solution:

y[x_] = 
      a0 + a1*x + (a2/2!)*x^2 + (a3/3!)*x^3 + (a4/4!)*
          x^4 + O[x]^5

Remove["a*"]

Second solution.

First let us make up a series which coefficients we have to determine, let us consider the first 10 coefficients:

ser = Sum[a[n] x^n, {n, 0, 10}] + O[x]^10

Then we substitute this series into the differential equation:

difeq =  D[ser,{x,2}]-x*D[ser,x] +Exp[x]*ser == 4

Coef = LogicalExpand[ difeq  ]

The initial value condition and the first equation in the last expression give us immediately values of the a[0] and a[1]:

a[0] = 1;
a[1] = 4;

Now we can solve for all other cefficients:

coeffs = Solve[Coef, Table[a[i], {i,2,9}]]

Finally let us write down the answer:

y = ser /. coeffs

Remove["a*"]