Solving the Heat Equation (Dirichlet case) in 2 Dimensions using the Discrete Sine Transform
Contents
You first have to download m-files
Download the m-files sintr.m , isintr.m and put them in the same directory as your other m-files.
Solve the heat equation
in a rectangle
The temperature in a rectangular plate is described by a function for
,
,
.
We assume that the temperature is zero on all four sides of the rectangle (Dirichlet conditions). The initial temperature is given.
The function satisfies the heat equation:
We have Dirichlet boundary conditions on all four sides of the rectangle for all :
We write the solution as a sine series with respect to both x and y: With
and
From this we get and
This gives the following Solution Formula: First find the sine series of with respect to both x and y:
Then the solution is given by
Example: For a rectangle with lengths and
we are given the initial condition
with
A=3; B=2; % lengths of rectangle sides g = @(x,y) double((x>2)|(y>1)); % given function g(x,y) for initial condition M = 100; % use spacing A/M for x x = A*(1:M-1)/M; % only interior nodes N = 100; % use spacing B/N for y y = B*(1:N-1)/N; % only interior nodes [X,Y] = ndgrid(x,y); % X,Y are arrays of size M by N G = g(X,Y); % G is array of values of g on grid: G(j,k) = g(x_j,y_k) surf(x,y,G'); xlabel('x'); ylabel('y'); title('given initial temperature')

Use the discrete sine transform to compute the solution at several times
tv = [.005 .05]; % find solutions for these times bx = sintr(G); % apply sine transform to columns b = sintr(bx')'; % apply sine transform to rows mu = (1:M-1)*pi/A; % vector of mu_k nu = (1:N-1)*pi/B; % vector of nu_l [Mu,Nu] = ndgrid(mu,nu); % Mu,Nu are arrays of size M by N for t=tv % for all times in vector tv C = b.*exp(-t*(Mu.^2+Nu.^2)); % solution formula in frequency domain Cx = isintr(C')'; % apply inverse sine transform to rows U = isintr(Cx); % apply inverse sine transform to columns surf(x,y,U'); % make surface plot of solution xlabel('x'); ylabel('y'); title(sprintf('temperature at time %g',t)) snapnow % show current figure end

