+ All Categories
Home > Documents > Partial Differential Equations (PDEs) and the ... - MATLAB

Partial Differential Equations (PDEs) and the ... - MATLAB

Date post: 03-Oct-2021
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
14
Page | 1 Partial Differential Equations (PDEs) and the Finite Difference Method (FDM). An introduction Original: May 7, 2015 Revised: Dec 19, 2016, Feb 20, 2017 The FDM The main feature of the finite difference method is to obtain discrete equations by replacing derivatives and other elements within the equation with appropriate finite divided differences and discrete approximations. We derive and solve a finite difference system for the PDE in five steps. 1. Discretization of the domain of the problem 2. Discretization of the differential equation at the interior nodes 3. Discretization of the boundary conditions. 4. Construction of the system of equations and/or the matrix form. 5. Solving the equations Many times the system of linear equations is tridiagonal and the solution of tridiagonal linear systems is a very well-studied problem. Other times we do not need to solve a matrix. The Heat Conduction Equation in One-Dimension One of the simplest PDEs to learn the numerical solution process is the problem posed by the heat conduction equation in one dimension: Eq-1 The โ€˜Toyโ€™ Problem Description-A Quick-Example For the Heat Equation above, a parabolic PDE governing the temperature distribution of a thin rod insulated at all points, except at its ends with the following specifications: โ€ข L = 3 cm (rod length) โ€ข โˆ†x = 1 cm, โˆ†t = 0.1 s, k = 0.835 cm 2 /s (thermal diffusivity), and โ€ข ฮป = โˆ†/โˆ† 2 =0.835(0.1)/(1) 2 = 0.0835
Transcript
Page 1: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 1

Partial Differential Equations (PDEs) and the Finite Difference Method (FDM). An introduction

Original: May 7, 2015

Revised: Dec 19, 2016, Feb 20, 2017

The FDM

The main feature of the finite difference method is to obtain discrete equations by replacing derivatives

and other elements within the equation with appropriate finite divided differences and discrete

approximations. We derive and solve a finite difference system for the PDE in five steps.

1. Discretization of the domain of the problem

2. Discretization of the differential equation at the interior nodes

3. Discretization of the boundary conditions.

4. Construction of the system of equations and/or the matrix form.

5. Solving the equations

Many times the system of linear equations is tridiagonal and the solution of tridiagonal linear systems is

a very well-studied problem. Other times we do not need to solve a matrix.

The Heat Conduction Equation in One-Dimension

One of the simplest PDEs to learn the numerical solution process is the problem posed by the heat

conduction equation in one dimension:

Eq-1

The โ€˜Toyโ€™ Problem Description-A Quick-Example

For the Heat Equation above, a parabolic PDE governing the temperature distribution of a thin rod

insulated at all points, except at its ends with the following specifications:

โ€ข L = 3 cm (rod length)

โ€ข โˆ†x = 1 cm, โˆ†t = 0.1 s, k = 0.835 cm2/s (thermal diffusivity), and

โ€ข ฮป = ๐‘˜โˆ†๐‘ก/โˆ†๐‘ฅ2=0.835(0.1)/(1)2 = 0.0835

Page 2: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 2

At t = 0, the temperature of interior nodes of the rod is zero and the boundary conditions are fixed for

all times. These can be expressed as

โ€ข U(x,0) = 0 oC for 0<x<3

โ€ข U(0,t) = 5 oC for t>0

โ€ข U(3,t) = 10 oC for t>0

All following methods below refer to the same problem description above

Discretize the domain of the problem. For two independent variables use a mesh grid, each axis

representing one of them. Use as running indices, i for space and k for time, e.g., i=0,1,2,โ€ฆ ix, and

k=0,1,2,โ€ฆ,kx.

A more detailed discretization showing the computational molecule (dashed shape) for the FTCS

method (to be discussed later):

Page 3: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 3

Discuss: A good discretization should include a cartoon representation of the number of grid nodes,

the step size, indexed nodes, and the computational molecule.

At a given time point, how many times the computational molecule fits into the grid?

How many unknowns must be solved at each given time point? How many equations do you

need?

Regarding the discrete equations is there any difference if the running index starts at 0 or at 1?

What is the range of the running index?

What specific indexed variables correspond to boundary conditions (BCs)? How the indices

change if they start at 0 or at 1?

Next is the description of the three main methods used for numerical solution of the heat equation

Forward in time, centered in space (FTCS) Solution. This method is also called forward Euler method.

Using the domain discretization described above, the steps toward the solution are:

(1) Discretize the differential equation

a. Approximate the 1st order time derivative with forward finite difference approximation

of ๐œ—(โˆ†๐‘ก) at the grid point (i,k):

๐œ•๐‘ˆ

๐œ•๐‘ก|

๐‘–,๐‘˜=

๐‘ˆ๐‘–๐พ+1 โˆ’ ๐‘ˆ๐‘–

๐พ

โˆ†๐‘ก

Notice the presence of indices (i,k) at the LHS derivative operator. These means the

discretization is at the node (i,k).

b. Approximate the 2nd order space derivative with central difference approximation of

๐œ—(โˆ†๐‘ฅ2) at the grid point (i,k):

๐œ•2๐‘ˆ

๐œ•๐‘ฅ2|

๐‘–,๐‘˜

=๐‘ˆ๐‘–+1

๐พ โˆ’ 2๐‘ˆ๐‘–๐พ + ๐‘ˆ๐‘–โˆ’1

๐พ

โˆ†๐‘ฅ2

Page 4: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 4

c. Plug (a) and (b) results in the original equation (Eq-1) to find the recurrence formula:

๐‘ˆ๐‘–๐พ+1 โˆ’ ๐‘ˆ๐‘–

๐พ

โˆ†๐‘ก= ๐‘˜

๐‘ˆ๐‘–+1๐พ โˆ’ 2๐‘ˆ๐‘–

๐พ + ๐‘ˆ๐‘–โˆ’1๐พ

โˆ†๐‘ฅ2

which yields the recurrence formula:

๐‘ˆ๐‘–๐พ+1 = ๐‘ˆ๐‘–

๐พ + ๐œ†(๐‘ˆ๐‘–+1๐พ โˆ’ 2๐‘ˆ๐‘–

๐พ + ๐‘ˆ๐‘–โˆ’1๐พ ), where ๐œ† = ๐‘˜โˆ†๐‘ก/โˆ†๐‘ฅ2 Eq #4a

Grouping variables with same indices offer another way to express the recurrence formula which is

more suitable for a computer program:

๐‘ˆ๐‘–๐พ+1 = ๐œ†๐‘ˆ๐‘–โˆ’1

๐พ + (1 โˆ’ 2๐œ†)๐‘ˆ๐‘–๐พ + ๐œ†๐‘ˆ๐‘–+1

๐พ Eq #4b

The recurrence formula is written for all the interior nodes on the rod by properly setting values of i and

K. It then provides an explicit means to compute values at each node for a future time (K+1) based on

the present values (K) at the node and its neighbors. Notice that this approach is actually an extension

of Eulerโ€™s method for solving the ODE at several nodes in space. That is, if we know the temperature

distribution as a function of position at an initial time, we can compute the distribution at a future time

based on Equation #4.

(2) Discretize the initial and boundary conditions (i.e., express the discrete variables involved with

right indices):

Original Mathematical Expression Discretized

๐‘ˆ(0, ๐‘ก) = 5 ๐‘ˆ๐‘œ๐‘˜ = 5 for ๐‘˜ โ‰ฅ 0 (๐‘–. ๐‘’., ๐‘˜ = 0,1,2,3, โ€ฆ )

๐‘ˆ(3, ๐‘ก) = 10 ๐‘ˆ3๐‘˜ = 10 for ๐‘˜ โ‰ฅ 0 (๐‘–. ๐‘’., ๐‘˜ = 0,1,2,3, โ€ฆ)

๐‘ˆ(๐‘ฅ, 0) = 0 ๐‘ˆ๐‘–0 = 0 for 0 < ๐‘– < 3 (๐‘–. ๐‘’, ๐‘– = 1,2)

(3) Show the FTCS computational molecule within the grid of your discretization (see discretization

above)

(4) Develop the equations to be solved According to the problem discretization and the number of

unknowns, and using the recurrence formulation (Eq #4b), find the appropriate number of

equations for the solutions at the first and second time steps. Please use algebraic expressions

with indixed variables, NO numbers yet:

For the first time step [t1=0.1]:

i=1, k=0:

๐‘ˆ11 = ๐‘ˆ1

0 + ๐œ†(๐‘ˆ20 โˆ’ 2๐‘ˆ1

0 + ๐‘ˆ00),

i=2, k=0:

๐‘ˆ21 = ๐‘ˆ2

0 + ๐œ†(๐‘ˆ30 โˆ’ 2๐‘ˆ2

0 + ๐‘ˆ10),

For the second time step [t2=0.2]:

Page 5: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 5

i=1, k=1:

๐‘ˆ12 = ๐‘ˆ1

1 + ๐œ†(๐‘ˆ21 โˆ’ 2๐‘ˆ1

1 + ๐‘ˆ01)

i=2, k=1:

๐‘ˆ22 = ๐‘ˆ2

1 + ๐œ†(๐‘ˆ31 โˆ’ 2๐‘ˆ2

1 + ๐‘ˆ11)

Quiz:

Locate each ๐‘ˆ๐‘–๐‘˜ in the above equations within its computational molecule and the mesh grid.

How do you give specificic values to i- and K-indices in the recurrence formula to arrive to the

above equations. Realize, that after given the correct values for i and K, each ๐‘ˆ๐‘–๐พin the equation

is represented in the computational molecule (cm) ; each element is bounded, i.e., no ๐‘ˆ๐‘–๐พ is

outside the cm. For instance, study the following figure for the first equation above (i.e., ๐‘ˆ11):

(5) Plugging numbers in the equations developed in (4), solve for two time steps (i.e.,[ t1 ,U(xi, t1 ),

and [t2 ,U(xi, t2 )]:

For the first time step [t1=0.1]:

๐‘ˆ11 = ๐‘ˆ1

0 + ๐œ†(๐‘ˆ20 โˆ’ 2๐‘ˆ1

0 + ๐‘ˆ00) = 0 + 0.0835(0 โˆ’ 2(0) + 5) = 0.4175

๐‘ˆ21 = ๐‘ˆ2

0 + ๐œ†(๐‘ˆ30 โˆ’ 2๐‘ˆ2

0 + ๐‘ˆ10) = 0 + 0.0835(10 โˆ’ 2(0) + 0) = 0.835

For the second time step [t2=0.2]:

Page 6: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 6

๐‘ˆ12 = ๐‘ˆ1

1 + ๐œ†(๐‘ˆ21 โˆ’ 2๐‘ˆ1

1 + ๐‘ˆ01) = 0.4175 + 0.0835(0.835 โˆ’ 2(0.4175) + 5) = 0.835

๐‘ˆ22 = ๐‘ˆ2

1 + ๐œ†(๐‘ˆ31 โˆ’ 2๐‘ˆ2

1 + ๐‘ˆ11) = 0.835 + 0.0835(10 โˆ’ 2(0.835) + 0.4175) = 1.565416

(6) Express the results on a table (critical step). For example for the FTCS computation we can use

Excel (see the file: FDM with Excel):

Due to โ€˜top to downโ€™ custom calculations, notice the computational molecule โ€œup-side-downโ€

when compared to the mesh grid.

(7) Life Saver Matlab code. A better tool is a matlab code (see Appendix one).

(8) Convergence & Stability: Convergence means that as โˆ†x and โˆ†t approach zero, the results of the

finite-difference technique approach the true solution. Stability means that errors at any stage

of the computation are not amplified but are attenuated as the computations progress.

It can be shown that the explicit method is both convergent and stable if: ๐œ† = ๐œ…ฮ”๐‘ก/ฮ”๐‘ฅ2 โ‰ค 1/2

or โˆ†๐‘ก โ‰ค1

2

โˆ†๐‘ฅ2

๐‘˜ (this means you canโ€™t march the solution in a time faster than

1

2

โˆ†๐‘ฅ2

๐‘˜ )

Crank Nicolson Method (CNM). Now we deal with the CNM as the more accurate and popular method

used to solve this type of equation. Use the same problem domain discretization as above.

(1) Discretization of the Differential equation. Evaluation of the ๐œ•2๐‘ˆ

๐œ•๐‘ฅ2 at both time steps ๐‘ก๐‘˜+1 and

time step ๐‘ก๐‘˜ and doing a weighted average with the ๐œƒ factor yields the following:

๐‘ˆ๐‘–๐‘˜+1 โˆ’ ๐‘ˆ๐‘–

๐‘˜

โˆ†๐‘ก= ๐œƒ๐‘˜ [

๐‘ˆ๐‘–โˆ’1๐‘˜+1 โˆ’ 2๐‘ˆ๐‘–

๐‘˜+1 + ๐‘ˆ๐‘–+1๐‘˜+1

โˆ†๐‘ฅ2] + (1 โˆ’ ๐œƒ)๐‘˜ [

๐‘ˆ๐‘–โˆ’1๐‘˜ โˆ’ 2๐‘ˆ๐‘–

๐‘˜ + ๐‘ˆ๐‘–+1๐‘˜

โˆ†๐‘ฅ2]

a. The recurrence formula with ๐œƒ = 1/2 is:

โˆ’ (1

2) ๐œ†๐‘ˆ๐‘–โˆ’1

๐‘˜+1 + (1 + ๐œ†)๐‘ˆ๐‘–๐‘˜+1 โˆ’ (

1

2) ๐œ†๐‘ˆ๐‘–+1

๐‘˜+1 = (1

2) ๐œ†๐‘ˆ๐‘–โˆ’1

๐‘˜ + (1 โˆ’ ๐œ†)๐‘ˆ๐‘–๐‘˜ + (

1

2) ๐œ†๐‘ˆ๐‘–+1

๐‘˜

the above equation times 2, simplifies to:

โˆ’๐œ†๐‘ˆ๐‘–โˆ’1๐‘˜+1 + 2(1 + ๐œ†)๐‘ˆ๐‘–

๐‘˜+1 โˆ’ ๐œ†๐‘ˆ๐‘–+1๐‘˜+1 = ๐œ†๐‘ˆ๐‘–โˆ’1

๐‘˜ + 2(1 โˆ’ ๐œ†)๐‘ˆ๐‘–๐‘˜ + ๐œ†๐‘ˆ๐‘–+1

๐‘˜

NOTE: You donโ€™t need to rename coefficients as they are simple enough.

x(0)=0 x(1)=1 x(2)=2 x(3)=3

K\i ==> 0 1 2 3

t(0)=0 0 5 0 0 10

t(1)=0.1 1 5 0.4175 0.835 10

t(2)=0.2 2 5 0.835 1.565416 10

t(3)=0.3 3 5 1.243767 2.208714 10

t(4)=0.4 4 5 1.637986 2.778714 10

Page 7: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 7

Where the coefficients for the current problem are:

2(1 + 0.0835) = 2.167

2(1 โˆ’ 0.0835) = 1.833

๐œ† = 0.0835

(2) Discretize the initial and boundary conditions (This is the same as FTCS method).

(3) Show the CN computational molecule within the grid of your discretization.

(4) According to your problem discretization and the number of unknowns find the appropriate

number of equations to solve for the first time step. We use indexed-variable algebraic

equationsโ€”Not numbers yet:

For the time ๐‘ก1, there are two unknowns, ๐‘ข11 and ๐‘ข2

1, therefore, we need two equations to solve

them:

Set i=1 and k=0 in the recurrence formula:

โˆ’๐œ†๐‘ˆ01 + 2(1 + ๐œ†)๐‘ˆ1

1 โˆ’ ๐œ†๐‘ˆ21 = ๐œ†๐‘ˆ0

0 + 2(1 โˆ’ ๐œ†)๐‘ˆ10 + ๐œ†๐‘ˆ2

0

Notice that with these two indices values i=1 and k=0 we produced the two unknowns ๐‘ˆ11

and ๐‘ˆ21of the computational molecule.

Set i=2 and k=0 in the recurrence formula:

โˆ’๐œ†๐‘ˆ11 + 2(1 + ๐œ†)๐‘ˆ2

1 โˆ’ ๐œ†๐‘ˆ31 = ๐œ†๐‘ˆ1

0 + 2(1 โˆ’ ๐œ†)๐‘ˆ20 + ๐œ†๐‘ˆ3

0

Notice again that with these two indices values i=2 and k=0 we produced the two unknowns ๐‘ˆ11

and ๐‘ˆ21of the computational molecule, while the rest of ๐‘ˆ๐‘–

๐พare all known.

As the two terms ๐‘ˆ01 = 5 and ๐‘ˆ3

1 = 10 in the first and second equations above are knowns and

constant along the BCs, you must jump them to the RHS of the equation:

Page 8: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 8

2(1 + ๐œ†)๐‘ˆ11 โˆ’ ๐œ†๐‘ˆ2

1 = ๐œ†๐‘ˆ00 + 2(1 โˆ’ ๐œ†)๐‘ˆ1

0 + ๐œ†๐‘ˆ20 + ๐œ†๐‘ˆ0

1

โˆ’๐œ†๐‘ˆ11 + 2(1 + ๐œ†)๐‘ˆ2

1 = ๐œ†๐‘ˆ10 + 2(1 โˆ’ ๐œ†)๐‘ˆ2

0 + ๐œ†๐‘ˆ30 + ๐œ†๐‘ˆ3

1

(5) Express the problem with numbers for a clean system of linear equations and also in matrix

form:

2.167๐‘ˆ11 โˆ’ 0.0835๐‘ˆ2

1 = 0.0835(5) + 1.833(0) + 0.0835(0) + 0.0835(5) = 0.835

โˆ’0.0835๐‘ˆ11 + 2.167๐‘ˆ2

1 = 0.0835(0) + 1.833(0) + 0.0835(10) + 0.0835(10) = 1.67

The system of equations:

2.167๐‘ˆ11 โˆ’ 0.0835๐‘ˆ2

1 = 0.835

โˆ’0.0835๐‘ˆ11 + 2.167๐‘ˆ2

1 = 1.67

The matrix equation:

[2.167 โˆ’0.0835

โˆ’0.0835 2.167] [

๐‘ˆ11

๐‘ˆ21] = [

0.8351.67

]

(6) Solve the system of linear equations.

The current 2x2 system of equations, can be solved by many methods. For instance, by substitution.

Solve for ๐‘ˆ11 from the first equation and replaced it into the second equation, next solve by ๐‘ˆ2

1.

However, this is a โ€˜toyโ€™ problem and in real life problems matrices are many times larger. We are doing

this example to learn the procedure and be able to apply it to larger matrices, therefore be smarter and

run a simpler MATLAB script:

% CN-solution with matlab % File

clc, clear A=[2.167,-0.0835;-0.0835,2.167]; b=[0.835;1.67]; u=A\b

OUTPUT u =

0.4156

0.7867

IMPORTANT: The solution above represents only the interior nodes ๐‘ˆ11and ๐‘ˆ2

1 Adding the constant

BCs, the solution vector is then, u = [5, 0.4156, 0.7867, 10]. This last step is a critical one. Many

times students forget to express the whole solution, i.e., one that includes the known BCs.

(9) As engineers likes to organize their results, then express the results on a table.

Page 9: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 9

We have just solved the PDE for one time step. This process should be repeated more more time steps

until satisfying the requested time range (problem domain).

(10) Please review another example on the document: CRANK-Example with MATLAB code

(DOC)

Backward in time, centered in space (BTCS) method

(1) Discretization of the Differential equation.

a. Approximate the 1st order time derivative with backward difference approximation of

๐œ—(โˆ†๐‘ก) at the grid point (i,k+1):

๐‘ข๐‘–๐‘˜+1 โˆ’ ๐‘ข๐‘–

๐‘˜

โˆ†๐‘ก

b. Approximate the space derivative with central difference approximation of ๐œ—(โˆ†๐‘ฅ2) at

the grid point (i,k+1):

๐‘˜ [๐‘ข๐‘–โˆ’1

๐‘˜+1 โˆ’ 2๐‘ข๐‘–๐‘˜+1 + ๐‘ข๐‘–+1

๐‘˜+1

โˆ†๐‘ฅ2]

c. Plug results in (a) and (b) in the original equation heat equation (Eq-1)

๐‘ข๐‘–๐‘˜+1 โˆ’ ๐‘ข๐‘–

๐‘˜

โˆ†๐‘ก= ๐‘˜ [

๐‘ข๐‘–โˆ’1๐‘˜+1 โˆ’ 2๐‘ข๐‘–

๐‘˜+1 + ๐‘ข๐‘–+1๐‘˜+1

โˆ†๐‘ฅ2]

d. The recurrence formula

โˆ’๐œ†๐‘ข๐‘–โˆ’1๐‘˜+1 + (1 + 2๐œ†)๐‘ข๐‘–

๐‘˜+1 โˆ’ ๐œ†๐‘ข๐‘–+1๐‘˜+1 = ๐‘ข๐‘–

๐‘˜

(2) Discretize the initial and boundary conditions (same as FTCS method)

(3) Show the BTCS computational molecule within the grid of your discretization

k\ii 0 1 2 3

0 5 0 0 10

1 5 0.4156 0.7867 10

2 5 10

3 5 10

... ... ...

Page 10: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 10

(4) According to the problem discretization and the number of unknowns we should find the

appropriate number of equations using the recurrence formula. Equations with Indexed-

variable are usedโ€”NO numbers yet:

Set i=1, and k=0 in the recurrence formula

โˆ’๐œ†๐‘ข01 + (1 + 2๐œ†)๐‘ข1

1 โˆ’ ๐œ†๐‘ข21 = ๐‘ข1

0

Set i=2, and k=0 in the recurrence formula

โˆ’๐œ†๐‘ข11 + (1 + 2๐œ†)๐‘ข2

1 โˆ’ ๐œ†๐‘ข31 = ๐‘ข2

0

As ๐‘ข01 and ๐‘ข3

1 are known values the above equations simplify to:

(1 + 2๐œ†)๐‘ข11 โˆ’ ๐œ†๐‘ข2

1 = ๐‘ข10 + ๐œ†๐‘ข0

1

โˆ’๐œ†๐‘ข11 + (1 + 2๐œ†)๐‘ข2

1 = ๐‘ข20 + ๐œ†๐‘ข3

1

(5) Plugging numbers in equations in (4) and expressing the problem with numbers in a clean

system of linear equations and also in matrix form to solve it for the first step in time.

(1 + 2(0.0835))๐‘ข11 โˆ’ 0.0835๐‘ข2

1 = 0 + (0.0835)5

โˆ’0.0835๐‘ข11 + (1 + 2(0.0835))๐‘ข2

1 = 0 + (0.0835)10

Simplifying, yields the clean system:

1.167๐‘ข11 โˆ’ 0.0835๐‘ข2

1 = 0.4175

โˆ’0.0835๐‘ข11 + 1.167๐‘ข2

1 = 0.835

And the matrix form:

[1.167 โˆ’0.0835

โˆ’0.0835 1.167] [

๐‘ˆ11

๐‘ˆ21] = [

0.41750.835

]

Although in this toy problem we got a 2x2 matrix which does not display tridiagonal characteristics due

to โ€˜smallnessโ€™ be aware that in real problems these matrices are quite larger and tridiagonal.

(6) Solve the matrix by similar methods as the previous CN method.

Page 11: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 11

For diffusion equations (and many other equations), it can be shown the Crankโ€“Nicolson method is

unconditionally stable. However, the approximate solutions can still contain (decaying) spurious

oscillations if the ratio of time step ฮ”t times the thermal diffusivity to the square of space step, ฮ”x2, is

large (typically larger than 1/2 per Von Neumann stability analysis) [i.e., if ๐œ† =๐œ…ฮ”๐‘ก

ฮ”๐‘ฅ2 > 1/2]. For this

reason, whenever large time steps or high spatial resolution is necessary, the less accurate BTCS (also

called backward Euler method) is often used, which is both stable and immune to oscillations.

EXERCISES

1- Using FTCS method and matlab rework the toy problem with โˆ†x = 0.5 cm, โˆ†t = 0.1 s, ฮป =

kโˆ†t/โˆ†x2=0.835(0.1)/(0.5)2 = 0.334 in the range of 0 โ‰ค ๐‘ก โ‰ค 1

2- Discuss the error order of each method: FTSC, CN and BTCS

3- Classify the FTCS, CN, BTCS in implicit and explicit methods

REFERENCES AND EXTERNAL LINKS

1. Numerical PDF Techniques for Scientists and Engineers

http://www3.nd.edu/~dbalsara/Numerical-PDE-Course/

Page 12: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 12

APPENDIX ONE

Next is a matlab code, results and graph.

% FTCS Finite Difference Method and the Heat Equation

% file: heatConductionPDE3.m (Feb 20, 2017) % Use the explicit FTCS method to solve for the temperature distribution % of a thin rod insulated at all points, except at its ends with a % length L (or a SEMIinfinite slab-โ€losa, planchaโ€- with a width L) % L = 10 cm (rod length) % Assume: dx = 2 cm, dt = 0.1 s, k = 0.835 cm2/s, and % lambda = kdt/dx^2=0.835(0.1)/(2)^2 = 0.020875

% IC & BCs: % U(x,O)=0 C for 0<x<10

% U(0,t) = 100 C for t>0

% U(10,t) = 50 C for t>0 clc, clear, close % Define constants

L = 10; % length of domain in x direction

tmax = 12; % end time

dx = 2; dt = 0.1; ix = L/dx + 1; % ix = 6;number of nodes in x direction for current problem

kt = tmax/dt + 1; % if t(1)=0, kt = 121; %number of total time steps for current problem

% dx = L/(ix-1); step size in x dt = tmax/(kt-1); step size in t

k=0.835; % thermal diffusivity r = k*dt/dx^2; r2 = 1 - 2*r; % r = lambda % Nodes coordinates

ii=[1:ix]; kk=[1:kt]; % Table title (this section can be totally eliminated to erase headers) x=([1:ix]-1)*dx; fprintf(' x ==> '); fprintf('%10d ',x); fprintf('\n'); fprintf(' t, below'); % Initial condition & BCs

t(1)= 0; uold(1)=100; uold(2:1:ix-1)=0; uold(ix)=50;

Page 13: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 13

uu=zeros(kt,ix); uu(1,ii)=uold; fprintf('\n'); % --- Loop over time steps

for m=2:kt

% uold = u; % prepare for next step

t(m) = t(m-1) + dt; for i=2:ix-1 % only interior nodes

uold(i) = r*uold(i-1) + r2*uold(i) + r*uold(i+1); end uu(m,ii)=uold; end % Output

t=t'; % from row to column uuu=[t,uu]; % uuu stores whole solution: t plus u for jj=1:30:kt % Output selected results

for ii=1:ix+1 fprintf('%10.3f ', uuu(jj,ii)); end

fprintf('\n'); end

fprintf('\n'); % For the graph tPlot= 0:3:12; %up to t(kt) plot(x,uuu(31,2:7), '.b','markers',20) hold on

plot(x,uuu(61,2:7), '.r','markers',20) hold on

plot(x,uuu(91,2:7), '.g','markers',20) hold on

plot(x,uuu(121,2:7), '.m','markers',20) hold on line(x,uuu(31,2:7),'Color','b') line(x,uuu(61,2:7),'Color','r')

Page 14: Partial Differential Equations (PDEs) and the ... - MATLAB

P a g e | 14

line(x,uuu(91,2:7),'Color','g') line(x,uuu(121,2:7),'Color','m') title('U, Temperature Distribution'); ylabel('U'); xlabel('x'); legend('t = 3 s','t = 6 s','t = 9 s','t = 12 s'); grid on

OUTPUT

Selected Results are shown: First column is time, next six columns are temperatures

GRAPH OUTPUT


Recommended