Solving a Second Order Ordinary Differential Equation by the Finite Difference Method

We wish to solve the boundary value problem

with boundary values y = 2 at x - 1 and y = -1 at x = 3. The differential equation is of the general form of equation 11-9 with a = —(0.15—jc/2.3), b = 1 and c = 0. For this simple example, we will subdivide the x interval, jc = 1 to x = 3, into ten subintervals; thus h = 0.2 and the x values defining the subintervals (sometimes called the mesh points) are x\ = 1.0, x2 = 1.2, ..., Jtn = 3.0. We can now write an equation of the form yi-i +

for each subinterval. Since y is known at the ends of the interval, we need to write only nine simultaneous equations (e.g., at x2 = 1.2):

7, + ((0.2 )2(- 0.15 + xj/2.3) - 2)y2 +y3 = (0.2)2x2 (11-15)

- (2 - (0.15 -^/2.3)(0.2)2)J3 +J4 = (0.2)2x3 (11-16)

y9 (2 (0.15 - x,o /2.3)(0.2)2>,o + 711 = (0.2)2x10 (11-17)

79- 1.9577,0=1.112 (11-17b) These simultaneous equations can be expressed in matrix form:

1.985

1

0

0

0

0

0

0

0

x2

1.952 "

1

-1.982

1

0

0

0

0

0

0

x3

0.056

0

1

-1.978

1

0

0

0

0

0

x4

0.064

0

0

1

-1.975

1

0

0

0

0

*5

0.072

0

0

0

1

-1.971

1

0

0

0

x6

=

0.080

0

0

0

0

1

-1.968

1

0

0

x7

0.088

0

0

0

0

0

1

-1.964

1

0

x8

0.096

0

0

0

0

0

0

1

-1.961

1

x9

0.104

0

0

0

0

0

0

0

1

-1.957

*10.

1.112

and can be solved by any of the methods described in Chapter 9.

The elements of the coefficients matrix and the constants vector can be generated easily by means of the spreadsheet layout illustrated in Figure 11-10. The formulas in cells C9 and F9 are, respectively,

It is important to remember that the formulas for the first and last terms of the constants vector are different. The formula in cells G10:G16 is

=hA2*bb*x+hA2*cc while the formulas in cells G9 and G17 are, respectively,

=hA2*bb*x+hA2*cc-B16. Be careful not to Fill Down the wrong formula when constructing a worksheet.

1

A

B

C

D

E

F

G

BVP by Finite-Difference Method

2

General formula: y"+ ay= bx + c

3

Example; y"- (0.15-X/2.3)y = x

4

P =

0.151

■ I.

5

2.3 h =

0.2'

6

Matrix Constant x y a b c terms s

7

10

2

6

1.2

0.3717

1

0

-1.985

-1.952

9

1.4

0.4587

1

0

-1.982

0.056

1Q

1.6

0.5457

1

0

-1.978

0.064

11

18

0.6326

1

0

-1.975

0.072

12

2,0

0.7196

1

0

-1.971

0.080

13

2.2

0.0065

1

0

-1.968

0,008

14

2,4

0.8935

1

0

-1.964

0,096

15

2.6

0.9804

1

0

-1.961

0.104

16

2.8

1.0674

1

0

-1.957

1.112

3.0

-1

Figure 11-10. Portion of the spreadsheet to solve the second-order differential equation y" - (0.15 - x/2.3)y = x by using the finite-difference method, (folder 'Chapter 11 Examples', workbook 'ODE-BVP', worksheet 'Finite Difference 1')

Figure 11-10. Portion of the spreadsheet to solve the second-order differential equation y" - (0.15 - x/2.3)y = x by using the finite-difference method, (folder 'Chapter 11 Examples', workbook 'ODE-BVP', worksheet 'Finite Difference 1')

The coefficients matrix (Figure 11-11) was assembled from the values in columns F and G by entering the formula

=IF(ROW()-top=COLUMN()-left,lNDIRECT("F"&ROW()),IF(ABS((ROW()-top) -(COLUMN()-left))=1,1,0))

in cell 19 and filling the formula into the 9x9 matrix of cells I8:Q16 to produce the matrix shown in Figure 11-11. The cell 19 was assigned the name TopCell and the following named formulas were entered by using Insert-*Name->- Define... left: =COLUMN(TopCell)

top: =ROW(TopCell)

J I J .

K

L

M

N

0

P

Q

6

Cefficients matrix

7

8

-1.985

1

0

0

0

0

0

Û

0

9

1

-1.982

1

0

o

0

0

0

0

10

0

1

-1.978

1

0

0

0

0

0

11

0

0

-1.975

1

0

0

0

0

12

0

0

0

1

-1.971

1

0

0

0

13

0

0

0

0

1

-1.968

1

0

0

14

0

0

0

0

0

1

-1,964

1

0

15

0

0

0

0

0

o

1

-1.961

1

16

0

0

0

0

0

0

0

1

-1.957

Figure 11-11. Coefficients matrix to solve the second-order differential equation y" - (0.15 -x/2.3)y = x by using the finite-difference method. The matrix is generated from the matrix terms in column F of Figure 11-10, then Fill Right, (folder 'Chapter 11 Examples', workbook 'ODE-BVP', worksheet 'Finite Difference 1')

The solution vector was produced by the array formula {=MMULT(MINVERSE(I9:Q17),G9:G17)}

J

6

Results

7

2.0

8

1.360

"9

0.748

10

. Q i7g

11

-0.332

12

-0.762

13

-1.069

14

-1.294

15

-1.356

16

-1 261

17

-1.0

Figure 11-12. Results vector for the second-order differential equation y" - (0.15 - x/2.3)y = x solved by using the finite-difference method, (folder 'Chapter 11 Examples', workbook 'ODE-BVP', worksheet 'Finite Difference 1')

Was this article helpful?

0 0

Post a comment