Numerical Methods for Partial Differential Equations
MATH 589

Fall 2013
% Demonstration for solving the heat equation.
%
% set the grid size
J=100; dx=1./J;
% set the initial conidtion in 'U' and is overwritten each time step
x = dx*(0:J);
U = [0 ones(1,J1) 0];
% define a new variable to store new values of U;
Unew=U;
mu = 0
Numerical Methods for Partial Differential Equations
MATH 589

Fall 2013
%Solving the Heat Equation using Crank Nicholson Scheme
tic
G = zeros(1,4); %will be used for showing convergence order of scheme
for M = 0:3
et number of space intervals
J=160*2^M; dx=1./J;
% set the initial condition
x = dx*(0:J);
U = x.*(1x);
mu = 5;
Numerical Methods for Partial Differential Equations
MATH 589

Fall 2013
function y=sfupwind(x,N,U,nu)
y=U;
for i=1:N
y(2:end1)=(y(2:end1).*(1+nu*(y(2:end1)y(3:end).*(1sign(y(2:end1).
+y(2:end1).*(1nu*(y(2:end1)y(1:end2).*(1+sign(y(2:end1)/2;
end
function y=sfnewton(x,t,U0)
u0=U0;
fx1=exp(40*(xt*u01).^2);
fpx=1