function twoRegionExample
a=0; b=1; c=3;
x2=linspace(b,c,20);
N1=10;
x = [linspace(a,b,N1) x2(2:end)];
t = linspace(0,.05,50);
A=10; B=2;
pdeFunc = @(x,t,u,DuDx) heatpde(x,t,u,DuDx,b);
icFunc = @(x) heatic(x, A,B, b);
bcFunc = @(xl,ul,xr,ur,t) heatbc(xl,ul,xr,ur,t,A,B);
m=0;
u = pdepe(m, pdeFunc,icFunc,bcFunc,x,t);
figure; plot(x, u(1,:)); grid on;
title 'initial value'; xlabel 'x';
figure; plot(x, u(end,:)); grid on;
title 'solution at final time'; xlabel 'x';
figure; plot(t, u(:,N1)); grid on;
title 'solution at x=b as a function of time'; xlabel 'time';
end
function [c,f,s] = heatpde(x,t,u,DuDx,b)
c = 1;
D1=10; D2=3;
if(x < b)
f = D1*DuDx;
else
f = D2*DuDx;
end
s = 0;
end
function u0 = heatic(x,T1,T2,b)
if(x < b)
u0 = T1;
else
u0 = T2;
end
end
function [pl,ql,pr,qr] = heatbc(xl,ul,xr,ur,t,A,B)
pl = ul-A;
ql = 0;
pr = ur-B;
qr = 0;
end