Solving the Heat Equation (DD case) using the Discrete Sine Transform

Contents

You first have to download m-files

Download the m-files sintr.m , isintr.m , colorcurves.m and put them in the same directory as your other m-files.

Solve heat equation $u_t = u_{xx}$

We want to find a function $u(x,t)$ for $x\in [0,1]$, $t\in[0,\infty)$ such that

$$u_t(x,t) = u_{xx}(x,t) \qquad x\in (0,1)$, $t\in(0,\infty) \quad\mbox{(PDE)}$$

$$u(x,0) = g(x) \qquad x\in (0,1) \quad\mbox{(Initial Condition)}$$

where $g(x)$ is a given function on $(0,1)$.

Boundary conditions: At the endpoints we have DIRICHLET conditions $u(0,t)=0$ and $u(1,t)=0$.

The method of Separation of Variables gives the following Solution Formula:

First find the sine series $g(x)=\sum_{k=1}^\infty b_k \sin(k\pi x)$. Let $\mu_k:=k\pi$ for $k=1,2,\ldots$. Then the solution $u(x,t)$ is given by

$$u(x,t) = \sum_{k=1}^\infty b_k \sin(\mu_k x)\cdot \exp(-\mu_k^2 t)$$

Example: given initial temperature $g(x)=x$

fct = @(x) x;                  % given function for initial temperature
N = 100;                       % use spacing 1/100 for x
x = (1:N-1)'/N;                % only interior nodes            (column vector)
g = fct(x);                    % evaluate g for 1/N,...,(N-1)/N (column vector)

b = sintr(g);                  % take Discrete Sine Transform

t = 0:.005:.05;                % find solution for these t-values (row vector)
kv = (1:N-1)';                 % column vector of k-values
muv = kv*pi;                   % column vector of mu-values
W = exp(-muv.^2*t);            % array of exp(-mu_k^2*t) for k=1...N-1, for all t-values
                               % (column vector)*(row vector) gives array
U = isintr(diag(b)*W);         % multiply 1st row by b(1), 2nd row by b(2), ...
                               % then take Inverse Sine Transform of each column

colorcurves(x,t,U); axis tight
xlabel('x'); ylabel('t'); title('temperature u(x,t) for t=0,.005,...,.05')

Show solution as graph over (x,t) plane

view(160,30)