Finite Difference Method

1 1D Heat Equation

[ = ]

Central difference in space:

[ ]

Explicit Euler in time:

[ T_i^{n+1} = T_i^n+ ( T_{i+1}n-2T_in+T_{i-1}^n ) ]

2 Stability

[ Fo= ]

For explicit 1D conduction:

[ Fo ]

For 2D equal grid spacing:

[ Fo ]

3 Julia Example

using Plots

function heat1d(; L=1.0, Nx=51, α=1e-4, dt=0.1, t_end=100.0)
    dx = L/(Nx-1)
    x = range(0, L, length=Nx)
    Fo = α*dt/dx^2

    T = fill(20.0, Nx)
    T[div(Nx,2)] = 100.0

    Nt = Int(round(t_end/dt))

    for n in 1:Nt
        Tnew = copy(T)
        for i in 2:Nx-1
            Tnew[i] = T[i] + Fo*(T[i+1]-2T[i]+T[i-1])
        end
        Tnew[1] = Tnew[2]
        Tnew[end] = Tnew[end-1]
        T = Tnew
    end

    return x, T
end

x, T = heat1d()
plot(x, T, xlabel="x", ylabel="T")