Trinh @ Bath

MA20223 Lecture 23

The 1D heat equation with zero Dirichlet conditions

We will complete our determination of the Fourier series solution of the heat equation as presented in the previous lecture. This was the problem of: $$ \begin{gathered} u_t = \kappa u_{xx}, \quad x\in[0, \pi], t \geq 0 \\ u(0, t) = 0 = u(\pi, t) \\ u(x, 0) = f(x) = 1. \end{gathered} $$

$$ u(x, t) \sim \sum_1^\infty \left[b_n \sin\left(\frac{n\pi x}{L}\right)\right]. $$

where $b_n$ will be the Fourier sine coefficients of the odd $2\pi$ extension of $f(x)$ on $[0, \pi]$.

The hardest part is to understand how to calculate the $b_n$ coefficients via an odd extension of the initial condition. In many ways, this is somewhat backwards (usually we ask “How do I compute a Fourier series for an odd extension” rather than to associate a Fourier series already given to an odd extension).

Anyways, this we do in the video, and there we show that $$ b_n = -\frac{2}{n\pi}[(-1)^n - 1] $$

We'll then share a numerical simulation of this heat flow problem in the lecture. The code is below.

Solution of 1D heat equation with zero Dirichlet

% Written for MA20223 Vectors & PDEs
clear           % Clear all variables
close all       % Close all windows

N = 20;          % How many Fourier modes to include?

% Define an in-line function that takes in three inputs: 
%   Input 1: n value [scalar]
%   Input 2: x value [vector]
%   Input 3: t value [scalar]
R = @(n, t, x) -2/(n*pi)*((-1)^n - 1)*exp(-n^2*t)*sin(n*x);

% Create a mesh of points between two limits
x0 = pi;
x = linspace(0, x0, 1000);

% Create a mesh of points in time
t = linspace(0, 5, 200);

figure(1);                                  % Open the figure
plot([0, pi], [1, 1], 'b', 'LineWidth', 2); % Plot the base function
ylim([-0.2,1.2]);                           % Set the y limits
xlim([0, x0]);                              % Set the x limits
xlabel('x'); ylabel('u(x,t)');
hold on
for j = 1:length(t)
    tj = t(j);
    
    u = 0;
    for n = 1:N
        u = u + R(n, tj, x);
    end
    
    % Plotting commands
    if j == 1
        p = plot(x, u, 'r');
    else
        set(p, 'YData', u);
    end
    drawnow
    title(['t = ', num2str(tj)]);
    pause(0.1);
   
    if j == 1
        pause
    end
end

The 1D heat equation with a steady state temperature

We will now examine the methodology for solving the non-homogeneous heat equation with Dirichlet conditions.

$$ \begin{gathered} u_t = \kappa u_{xx}, \quad x\in[0, L], t \geq 0 \\ u(0, t) = T_0, \quad u(L, t) = T_1 \\ u(x, 0) = f(x). \end{gathered} $$

The trick is to seek a steady state solution. Seek a solution that does not depend on time. Then $u(x, t) = U(x)$ and we must satisfy: $$ \begin{gathered} 0 = \kappa u_{xx}, \quad x\in[0, L], t \geq 0 \\ U(0) = T_0, \quad U(L) = T_1. \end{gathered} $$ The solution is then $U(x) = T_0 + (T_1 - T_0)x/L$.

Next, we set the solution as $$ u(x,t) = U(x) + \hat{u}(x,t). $$

Why do this? Substitute into the system now to see that $$ \begin{gathered} \hat{u}_t = \kappa \hat{u}_{xx}, \quad x\in[0, L], t \geq 0 \\ \hat{u}(0, t) = 0, \quad \hat{u}(L, t) = 0. \\ \hat{u}(x, 0) = f(x) - U(x). \end{gathered} $$

In other words, the effect of the trick of writing the solution using the steady-state $U(x)$ has effectively zero'ed the boundary conditions. So we can simply use the same techniques as developed above for the zero Dirichlet problem.

The algorithm is summarised in the video, and we will complete the demonstration in Friday's class.