[go: up one dir, main page]

0% found this document useful (0 votes)
55 views16 pages

Lecture Introduction To 1D Finite Difference Method

The document provides an introduction to the One-Dimensional Finite-Difference Method used for obtaining numerical solutions to differential equations. It outlines the conventional and improved methods, detailing steps such as identifying governing equations, approximating derivatives, and setting up a grid for calculations. The process culminates in solving a matrix equation to find the numerical solution for the given boundary values.

Uploaded by

Hassan Al Baity
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views16 pages

Lecture Introduction To 1D Finite Difference Method

The document provides an introduction to the One-Dimensional Finite-Difference Method used for obtaining numerical solutions to differential equations. It outlines the conventional and improved methods, detailing steps such as identifying governing equations, approximating derivatives, and setting up a grid for calculations. The process culminates in solving a matrix equation to find the numerical solution for the given boundary values.

Uploaded by

Hassan Al Baity
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

3/23/2023

Computational Science:
Computational Methods in Engineering

Introduction to One‐Dimensional
Finite‐Difference Method
1

Outline

• Introduction & Problem Setup


• Conventional Finite‐Difference Method
• Improved Finite‐Difference Method

1
3/23/2023

Introduction & Problem Setup

Slide 3

The Finite‐Difference Method


The finite‐difference method is a way of obtaining a numerical solution to differential
equations. It does not give a symbolic solution.

Governing Equation
d 2 y dy
 y0 0  x  10
dx 2 dx
y  0   1, y 10   5
Matrix Equation
 A y   b
Numerical Solution
 y    A  b 
1

Slide 4

2
3/23/2023

Functions are Discrete


To obtain a numerical solution using the finite‐difference method, functions are stored as
arrays of discrete points.

The function can be resolved more accurately using more points, but the solution will be
more computationally intensive to obtain. This is a fundamental tradeoff.

Slide 5

Discrete Functions are Stored as Column Vectors


Discrete functions are stored as a 1D array of numbers in a column vector.

d 2 y dy
  y0
dx 2 dx

 d2 d   
 2   1 y  0  
 dx dx   
 
 
 
 A y    0  y   
 
 
 
 
 
 
 

Slide 6

3
3/23/2023

Conventional
Finite‐Difference Method

Slide 7

Step 1 – Identify Governing Equation & Boundary


Values
Governing Equation
d 2 y dy
  y0 0  x  10
dx 2 dx

Boundary Values
y  0  1
y 10   5

Slide 8

4
3/23/2023

Step 2 – Approximate Derivatives with Finite‐


Differences (1 of 3)
First, let the function be discrete.

This allows the derivatives to be approximated with finite‐differences.

d 2 y dy
  y0
dx 2 dx

y  x  x   2 y  x   y  x  x  y  x   y  x  x 
  y  x  0
x 2 x

Slide 9

Step 2 – Approximate Derivatives with Finite‐


Differences (2 of 3)
It is critical to ensure that each term in the finite‐difference equation exists at the same point.

y  x  x   2 y  x   y  x  x  y  x   y  x  x 
  y  x  0
x 2 x
Exists at x Exists at 𝑥 Δ𝑥⁄2

Exists at x
This is not a healthy or stable formulation because
not all of the terms exist at the same point.
Exists at x

Slide 10

10

5
3/23/2023

Step 2 – Approximate Derivatives with Finite‐


Differences (3 of 3)
This is the correct finite‐difference equation.

d 2 y dy
 y0
dx 2 dx

y  x  x   2 y  x   y  x  x  y  x  x   y  x  x 
  y  x  0
x 2 2x

All terms exist at x.

Slide 11

11

Step 3 – Write Finite‐Difference Equation Using Array


Indices

d 2 y dy
 y0
dx 2 dx

y  x  x   2 y  x   y  x  x  y  x  x   y  x  x 
  y  x  0
x 2 2x

yi 1  2 yi  yi 1 yi 1  yi 1
  yi  0
x 2 2x

Slide 12

12

6
3/23/2023

Step 4 – Rearrange Finite‐Difference Equation


The finite‐difference equation is rearranged so as to collect the y terms.

yi 1  2 yi  yi 1 yi 1  yi 1
  yi  0
x 2 2x

1 2 1 1 1
y  2 yi  2 yi 1 
2 i 1
yi 1  yi 1  yi  0
x x x 2x 2x

 1 1   2   1 1 
 2  yi 1  1  2  yi   2   yi 1  0
 x 2x   x   x 2x 

Slide 13

13

Step 5 – Setup Grid


Solve this problem using 21 points.

x
x = 10
x=0

x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

The grid spacing x is then

xb  xa 10  0
x    0.5
N  1 21  1

Slide 14

14

7
3/23/2023

Step 6 – Revise Finite‐Difference Equation


Substituting x = 0.5 into the finite‐difference equation gives

 1 1   2   1 1 
 2  yi 1  1  2  yi   2   yi 1  0
 x 2x   x   x 2x 

 1 1   2   1 1 
 2  yi 1  1  2  yi   2   yi 1  0
 0.5 2  0.5   0.5   0.5 2  0.5 

5 yi 1  7 yi  3 yi 1  0

Slide 15

15

Step 7 – Write Finite‐Difference Equation at Each


Point on Grid

5 yi 1  7 yi  3 yi 1  0
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

These terms exist


outside of the grid.
Slide 16

16

8
3/23/2023

Step 8 – Incorporate Boundary Values

5 yi 1  7 yi  3 yi 1  0

y21 = 5
y1 = 1

x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Slide 17

17

Step 8 – Write Set of Equations as a Single Matrix


Equation
   y1  1 
   y  0 
  2   
   y3  0 
    
   y4   0 
   y5  0 
    
   y6  0 
   y  0 
  7   
   y8  0 
   y  0 
  9   
   y10  0 
    
   y11   0 
   y12  0 
    
   y13  0 
   y  0 
   14   
   y15  0 
   y  0 
   16   
   y17  0 
    
   y18  0 
   y19  0 
    
   y20  0 
   y21  5 

 A
 y b  Slide 18

18

9
3/23/2023

Step 9 – Solve Matrix Equation


1
 y1    1   1.0000 
y    0  
 2      2.0497 
 y3    0   3.1160 
       
 y4    0   3.8545 
 y5    0   3.8005 
       
 y6    0   2.4436 
y    0   -0.6324 
 7      
 y8    0   -5.5482 
y    0   -11.8919 
 9      
 y10    0   -18.5007 
       
 y11     0    -23.3484 
 y12    0   -23.6453 
       
 y13    0   -16.2582 
y    0   1.4730 
 14       
 y15    0   30.5339 
y    0   68.7909 
 16       
 y17    0   109.6222 
       
 y18    0   141.1336 
 y19    0   146.6082 
       
 y20    0   106.8630 
 y21    5   5.0000 

Slide 19

19

Step 10 – Plot the Result


 y1   1.0000 
 y   2.0497 
 2  
 y3   3.1160 
   
 y4   3.8545 
 y5   3.8005 
   
 y6   2.4436 
 y   -0.6324 
 7  
 y8   -5.5482 
 y  -11.8919 
 9  
 y10  -18.5007 
   
 y11   -23.3484 
 y12  -23.6453 
   
 y13  -16.2582 
 y   1.4730 
 14   
 y15   30.5339 
 y   68.7909 
 16   
 y17  109.6222 
   
 y18  141.1336 
 y19  146.6082 
   
 y20  106.8630 
 y21   5.0000 

Slide 20

20

10
3/23/2023

Improved
Finite‐Difference Method

Slide 21

21

Step 1 – Identify Governing Equation & Boundary


Values
Governing Equation
d 2 y dy
  y0 0  x  10
dx 2 dx

Boundary Values
y  0  1
y 10   5

Slide 22

22

11
3/23/2023

Step 2 – Write Equation in Matrix Form Going Term‐


by‐Term

d2 d
2
y  x  y  x  y  x  0
dx dx

 D 2x   y    D x  y    y    0

Slide 23

23

Step 3 – Factor Out [y] To Put in Standard Form

 D 2x   y    D x  y    y    0

 D   D    I  y  0


2
x x


 A y    0 standard form
 A   D2x    D x    I  A = DX2 - DX + I;

Slide 24

24

12
3/23/2023

Step 4 – Incorporate Boundary Values (1 of 4)


   y1  0 
   y  0
  2   
   y3  0 
    
   y4   0 
   y5  0 
    
   y6  0 
   y  0
  7   
Start with direct 

  y8  0 
  y  0
  9   
matrix equation.    y10  0 
    
   y11   0 

 A y   0 


  y12  0 
   
  y13  0 
   y  0
   14   
   y15  0 
   y  0
   16   
   y17  0 
 y   
   18  0 
   y19  0 
    
   y20  0 
   y21  0 

Slide 25

25

Step 4 – Incorporate Boundary Values (2 of 4)


   y1  0 
   y  0
  2   
   y3  0 
    
   y4   0 
   y5  0 
    
   y6  0 
   y  0
Zero out rows in [A] that 

 7   
  y8  0 
   y  0
correspond to the   9   
   y10  0 
boundary points. For this 

   
  y11   0 
case, these are the rows 

  y12  0 
   
   y13  0 
for y1 and y21.    y  0
   14   
   y15  0 
   y  0
   16   
   y17  0 
 y   
   18  0 
   y19  0 
    
   y20  0 
   y21  0 

Slide 26

26

13
3/23/2023

Step 4 – Incorporate Boundary Values (3 of 4)


   y1  0 
   y  0
  2   
   y3  0 
    
   y4   0 
   y5  0 
    
   y6  0 
   y  0
  7   
   y8  0 
Insert 1’s in the diagonal 

  y  0
 9   
position of the rows in [A] 

  y10  0 
   
   y11   0 
where zeros were inserted.    y12  0 
    
   y13  0 
   y  0
   14   
   y15  0 
   y  0
   16   
   y17  0 
 y   
   18  0 
   y19  0 
    
   y20  0 
   y21  0 

Slide 27

27

Step 4 – Incorporate Boundary Values (4 of 4)


   y1  1 
   y  0
  2   
   y3  0 
    
   y4   0 
   y5  0 
    
   y6  0 
   y  0
  7   
   y8  0 
   y  0
Insert boundary values in   9   
   y10  0 
column vector [b]. 

   
  y11   0 
   y12  0 
    
   y13  0 
   y  0
   14   
   y15  0 
   y  0
   16   
   y17  0 
 y   
   18  0 
   y19  0 
    
   y20  0 
   y21  5 

Slide 28

28

14
3/23/2023

Step 5 – Solve Matrix Equation


1
 y1    1   1.0000 
y    0  
 2      2.0497 
 y3    0   3.1160 
       
 y4    0   3.8545 
 y5    0   3.8005 
       
 y6    0   2.4436 
y    0   -0.6324 
 7      
 y8    0   -5.5482 
y    0   -11.8919 
 9      
 y10    0   -18.5007 
       
 y11     0    -23.3484 
 y12    0   -23.6453 
       
 y13    0   -16.2582 
y    0   1.4730 
 14       
 y15    0   30.5339 
y    0   68.7909 
 16       
 y17    0   109.6222 
       
 y18    0   141.1336 
 y19    0   146.6082 
       
 y20    0   106.8630 
 y21    5   5.0000 

Slide 29

29

Step 6 – Plot the Result


 y1   1.0000 
 y   2.0497 
 2  
 y3   3.1160 
   
 y4   3.8545 
 y5   3.8005 
   
 y6   2.4436 
 y   -0.6324 
 7  
 y8   -5.5482 
 y  -11.8919 
 9  
 y10  -18.5007 
   
 y11   -23.3484 
 y12  -23.6453 
   
 y13  -16.2582 
 y   1.4730 
 14   
 y15   30.5339 
 y   68.7909 
 16   
 y17  109.6222 
   
 y18  141.1336 
 y19  146.6082 
   
 y20  106.8630 
 y21   5.0000 

Slide 30

30

15
3/23/2023

31

16

You might also like