day27 pde heat equation implicit

Upload: cristian-paduraru

Post on 14-Apr-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    1/22

    Scientific Computing

    Partial Differential EquationsImplicit Solution of

    Heat Equation

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    2/22

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    3/22

    Explicit Method

    We use the centered-difference approximation

    for uxx at time step j:

    ui1, j

    2ui, j

    ui1, j

    h2

    grid point involved with space differencegrid point involved with time difference

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    4/22

    Implicit Method

    We use the centered-difference approximation

    for uxx at step (j+1) :

    ui1, j1

    2ui, j1

    ui1, j1

    h2

    grid point involved with space differencegrid point involved with time difference

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    5/22

    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,tj ) ui, j1 ui, j

    k

    cuxx(x i,tj ) cui1, j1 2ui, j1 ui1, j1

    h2

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    6/22

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

    Or,

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

    we get:

    Implicit Method

    ui, j1 ui, j

    k c

    ui1, j1 2ui, j1 ui1, j1

    h2

    ui, j1 uij ck

    h2ui1, j1 2ui, j1 ui1, j1

    ui, j rui1, j1 (12r)ui, j1 rui1, j1

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    7/22

    Putting in the boundary conditions, we get the

    following equations for the (implicit) solution to the

    heat equation is:

    Implicit Method

    ui, j rui1, j1 (12r)ui, j1 rui1, j1 j 0 i 2,K n 2u1, j rg0, j1 (12r)u1, j1 ru2, j1 j 0un1, j run2, j1 (1 2r)un1, j1 rg1, j1 j 0ui,0 fi i 0K n

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    8/22

    Matrix Form of Solution

    12r rr 1 2r r

    O O O

    r 12r r

    r 12r

    u1, j1

    u2, j1

    M

    un2, j1

    un1, j1

    rg0, j1

    0

    M

    0

    rg1, j1

    u1, j

    u2, j

    M

    un2, j

    un1, j

    ui, j rui1, j1 (12r)ui, j1 rui1, j1 j 0 i 2,K n 2u1, j rg0, j1 (12r)u1, j1 ru2, j1 j 0un1, j run2, j1 (1 2r)un1, j1 rg1, j1 j 0ui,0 fi i 0K n

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    9/22

    This is of the form

    To 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)

    12r r

    r 12r r

    O O O

    r 12r r

    r 12r

    u1, j1

    u2, j1

    M

    un2, j1

    un1, j1

    rg0, j10

    M

    0

    rg1, j1

    u1, j

    u2, j

    M

    un2, j

    un1, j

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    10/22

    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

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    11/22

    % 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

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    12/22

    % 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);

    endz=u';

    % plot solution in 3-d

    mesh(x,t,z);

    end

    Matlab Implementation

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    13/22

    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

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    14/22

    Calculated solution appears stable:

    Matlab Implementation

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    15/22

    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 rr 1 2r

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    16/22

    Thus, if is an eigenvalue of A, we have

    Thus, all eigenvalues are at least 1. In solving for u(:,j+1) in

    we have

    Since the eigenvalues of A-1 are the reciprocal of the

    eigenvalues of A, we have that the eigenvalues of A-1 are

    all

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    17/22

    Convergence means that as D x and D t approach zero,

    the results of the numerical technique approach the

    true solution

    Stabilitymeans that the errors at any stage of the

    computation are attenuated, not amplified, as the

    computation progresses

    Truncation Errorrefers to the error generated in thesolution by using the finite difference formulas for the

    derivatives.

    Convergence and Stability

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    18/22

    Example: For the explicit method, it will be stable if r

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    19/22

    Crank-Nicholson Method

    We average the centered-differenceapproximation

    for uxx at time steps j

    and j+1:

    ui1, j 2ui, j ui1, jh 2

    grid point involved with space difference

    grid point involved with time differenceui1, j1 2ui, j1 ui1, j1h2

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    20/22

    Crank-Nicholson Method

    We get the following

    ui, j1 uij ck

    2h

    2ui1, j 2ui, j ui1, j

    ck

    2h2ui1, j1 2ui, j1 ui1, j1

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    21/22

    Putting in the boundary conditions, we get the

    following equations for the (C-N) solution to the heat

    equation is:

    Crank-Nicholson Method

    r

    2ui1, j1 (1 r)ui, j1

    r

    2ui1, j1

    r

    2ui1, j (1 r)ui, j

    r

    2ui1, j

    r

    2

    g0, j1 (1 r)u1, j1 r

    2

    u2, j1

    r

    2

    g0, j (1 r)u1, j r

    2

    u2, j

    r

    2un2, j1 (1 r)un1, j1

    r

    2g1, j1

    r

    2un2, j (1 r)un1, j

    r

    2g1, j

    ui,0 fi

  • 7/27/2019 Day27 PDE Heat Equation Implicit

    22/22