Top Banner
Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation
22

Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Jan 02, 2016

Download

Documents

Margery Oliver
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Scientific Computing

Partial Differential EquationsImplicit Solution of

Heat Equation

Page 2: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Explicit vs Implicit Methods

• Explicit methods have problems relating to stability

• Implicit methods overcome this but at the expense of introducing a more complicated algorithm

• In the implicit algorithm, we develop simultaneous equations for u at the j-th and (j+1)-st time steps

Page 3: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Explicit Method

We use the centered-difference approximation for uxx at time step j:

ui−1, j − 2ui, j + ui+1, j

h2

grid point involved with space difference grid point involved with time difference

Page 4: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Implicit Method

We use the centered-difference approximation for uxx at step (j+1) :

ui−1, j+1 − 2ui, j+1 + ui+1, j+1

h2

grid point involved with space difference grid point involved with time difference

Page 5: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

• We use the forward-difference formula for the time derivative and the centered-difference formula for the space derivative at time step (j+1):

Implicit Method

ut (x i, t j ) ≅ui, j+1 − ui, j

k

cuxx (x i, t j ) ≅ cui−1, j+1 − 2ui, j+1 + ui+1, j+1

h2

Page 6: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

• Then the heat equation (ut =cuxx ) can be approximated as

Or,

Let r = (ck/h2) Solving for ui,j we get:

Implicit Method

ui, j+1 − ui, jk

= cui−1, j+1 − 2ui, j+1 + ui+1, j+1

h2

ui, j+1 − uij =ck

h2 ui−1, j+1 − 2ui, j+1 + ui+1, j+1( )

ui, j = −rui−1, j+1 + (1+ 2r)ui, j+1 − rui+1, j+1( )

Page 7: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

• Putting in the boundary conditions, we get the following equations for the (implicit) solution to the heat equation is:

Implicit Method

ui, j = −rui−1, j+1 + (1+ 2r)ui, j+1 − rui+1, j+1( ) j ≥ 0 i = 2,K n − 2

u1, j = −rg0, j+1 + (1+ 2r)u1, j+1 − ru2, j+1( ) j ≥ 0

un−1, j = −run−2, j+1 + (1+ 2r)un−1, j+1 − rg1, j+1( ) j ≥ 0

ui,0 = f i i = 0K n

Page 8: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Matrix Form of Solution

1+ 2r −r

−r 1+ 2r −r

O O O

−r 1+ 2r −r

−r 1+ 2r

⎢ ⎢ ⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥ ⎥ ⎥

u1, j+1

u2, j+1

M

un−2, j+1

un−1, j+1

⎜ ⎜ ⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟ ⎟ ⎟

+

−rg0, j+1

0

M

0

−rg1, j+1

⎜ ⎜ ⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟ ⎟ ⎟

=

u1, j

u2, j

M

un−2, j

un−1, j

⎜ ⎜ ⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟ ⎟ ⎟

ui, j = −rui−1, j+1 + (1+ 2r)ui, j+1 − rui+1, j+1( ) j ≥ 0 i = 2,K n − 2

u1, j = −rg0, j+1 + (1+ 2r)u1, j+1 − ru2, j+1( ) j ≥ 0

un−1, j = −run−2, j+1 + (1+ 2r)un−1, j+1 − rg1, j+1( ) j ≥ 0

ui,0 = f i i = 0K n

Page 9: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

This is of the formTo solve for u(:,j) we need to use a linear systems method.Since we have to solve this system repeatedly, a good choice

is the LU decomposition method.

Matrix Form of Solution

Au(:, j +1) +b = u(:, j)

1+ 2r −r

−r 1+ 2r −r

O O O

−r 1+ 2r −r

−r 1+ 2r

⎢ ⎢ ⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥ ⎥ ⎥

u1, j+1

u2, j+1

M

un−2, j+1

un−1, j+1

⎜ ⎜ ⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟ ⎟ ⎟

+

−rg0, j+1

0

M

0

−rg1, j+1

⎜ ⎜ ⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟ ⎟ ⎟

=

u1, j

u2, j

M

un−2, j

un−1, j

⎜ ⎜ ⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟ ⎟ ⎟

Page 10: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

function z = implicitHeat(f, g0, g1, T, n, m, c)%Simple Implicit solution of heat equation % Constants h = 1/n; k = T/m; r = c*k/h^2; % x and t vectors x = 0:h:1; t = 0:k:T; % Boundary conditions u(1:n+1, 1) = f(x)'; u(1, 1:m+1) = g0(t); u(n+1, 1:m+1) = g1(t);

Matlab Implementation

Page 11: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

% Set up tri-diagonal matrix for interior points of the grid A = zeros(n-1, n-1); % 2 less than x grid size for i= 1: n-1 A(i,i)= (1+2*r); if i ~= n-1 A(i, i+1) = -r; end if i ~= 1 A(i, i-1) = -r; end end % Find LU decomposition of A [LL UU] = lu_gauss(A); % function included below

Matlab Implementation

Page 12: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

% Solve for u(:, j+1); for j = 1:m % Set up vector b to solve for in Ax=b b = zeros(n-1,1); b = u(2:n, j)'; % Make a column vector for LU solver b(1) = b(1) + r*u(1,j+1); b(n-1) = b(n-1) + r*u(n+1,j+1); u(2:n, j+1) = luSolve(LL, UU, b); end z=u'; % plot solution in 3-d mesh(x,t,z);end

Matlab Implementation

Page 13: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Usage: f = inline(‘x.^4’); g0 = inline(‘0*t’); g1 = inline(‘t.^0’); n=5; m=5; c=1; T=0.5; z = implicitHeat(f, g0, g1, T, n, m, c);

Matlab Implementation

Page 14: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Calculated solution appears stable:

Matlab Implementation

Page 15: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

To analyze the stability of the method, we again have to consider the eigenvalues of A for the equation

We have

Using the Gershgorin Theorem, we see that eigenvalues are contained in circles centered at (1+2r) with max radius of 2r

Stability

Au(:, j +1) +b = u(:, j)

A =

1+ 2r −r

−r 1+ 2r −r

O O O

−r 1+ 2r −r

−r 1+ 2r

⎢ ⎢ ⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥ ⎥ ⎥

Page 16: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Thus, if λ is an eigenvalue of A, we have

Thus, all eigenvalues are at least 1. In solving for u(:,j+1) in we haveSince the eigenvalues of A-1 are the reciprocal of the

eigenvalues of A, we have that the eigenvalues of A-1 areall <= 1. Thus, the implicit algorithm yields stable iterates – they do

not grow without bound.

Stability

1+ 2r − 2r ≤ λ ≤1+ 2r + 2r

⇒ 1≤ λ ≤1+ 4r

Au(:, j +1) +b = u(:, j)

u(:, j +1) = A−1(u(:, j) −b)

Page 17: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

• Convergence means that as x and t approach zero, the results of the numerical technique approach the true solution

• Stability means that the errors at any stage of the computation are attenuated, not amplified, as the computation progresses

• Truncation Error refers to the error generated in the solution by using the finite difference formulas for the derivatives.

Convergence and Stability

Page 18: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Example: For the explicit method, it will be stable if r<= 0.5 and will have truncation error of O(k+h2) .

Implicit Method is stable for any choice of r and will again have truncation error of O(k+h2) .

It would be nice to have a method that is O(k2+h2). The Crank-Nicholson method has this nice feature.

Convergence and Stability

Page 19: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Crank-Nicholson Method

We average the centered-difference approximation

for uxx at time steps j and j+1:

ui−1, j − 2ui, j + ui+1, j

h2

grid point involved with space difference grid point involved with time difference

ui−1, j+1 − 2ui, j+1 + ui+1, j+1

h2

Page 20: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

Crank-Nicholson Method

We get the following

ui, j+1 − uij =ck

2h2 ui−1, j − 2ui, j + ui+1, j( )

+ck

2h2 ui−1, j+1 − 2ui, j+1 + ui+1, j+1( )

Page 21: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

• Putting in the boundary conditions, we get the following equations for the (C-N) solution to the heat equation is:

Crank-Nicholson Method

−r

2ui−1, j+1 + (1+ r)ui, j+1 −

r

2ui+1, j+1

⎝ ⎜

⎠ ⎟=r

2ui−1, j + (1− r)ui, j +

r

2ui+1, j

⎝ ⎜

⎠ ⎟

−r

2g0, j+1 + (1+ r)u1, j+1 −

r

2u2, j+1

⎝ ⎜

⎠ ⎟=r

2g0, j + (1− r)u1, j +

r

2u2, j

⎝ ⎜

⎠ ⎟

−r

2un−2, j+1 + (1+ r)un−1, j+1 −

r

2g1, j+1

⎝ ⎜

⎠ ⎟=r

2un−2, j + (1− r)un−1, j +

r

2g1, j

⎝ ⎜

⎠ ⎟

ui,0 = f i

Page 22: Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.

• Class Project: Determine the matrix for the C-N method and revise the Matlab implicitHeat function to implement C-N.

Crank-Nicholson Method

−r

2ui−1, j+1 + (1+ r)ui, j+1 −

r

2ui+1, j+1

⎝ ⎜

⎠ ⎟=r

2ui−1, j + (1− r)ui, j +

r

2ui+1, j

⎝ ⎜

⎠ ⎟

−r

2g0, j+1 + (1+ r)u1, j+1 −

r

2u2, j+1

⎝ ⎜

⎠ ⎟=r

2g0, j + (1− r)u1, j +

r

2u2, j

⎝ ⎜

⎠ ⎟

−r

2un−2, j+1 + (1+ r)un−1, j+1 −

r

2g1, j+1

⎝ ⎜

⎠ ⎟=r

2un−2, j + (1− r)un−1, j +

r

2g1, j

⎝ ⎜

⎠ ⎟

ui,0 = f i