% pdelampoDirichlet.m
% 12.3.05
% Kaikki tarvittavat alifunktioiksi

% Lämpöyhtälö: c=vakio, m=0, f(x,t,u,dudx)=dudx, s=0
% (AE) : u(x,t0)= u0(x)
function pdelampoDirichlet
close all
global x t u     % Ennen kutsua myös istunnossa, jos haluat jälkeenpäin käyttää.
m = 0;
x = linspace(0,1,20);
%t = linspace(0,1,5);
t = linspace(0,1,10);
sol = pdepe(m,@lampo,@AE,@RE,x,t);
% Extract the first solution component as u.

u = sol(:,:,1);

% A surface plot is often a good way to study a solution.
surf(x,t,u)    
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
% A solution profile can also be illuminating.
figure
plot(x,u(end,:))
title('Solution at t = 2')
xlabel('Distance x')
ylabel('u(x,2)')
% --------------------------------------------------------------
% Lämpöyhtälö: c=1 (huomaa: c on vasemmalla puolella, eli pi^2 u_t = u_xx
function [c,f,s] = lampo(x,t,u,DuDx)
c = 1;
f = DuDx;
s = 0;
% --------------------------------------------------------------
function u0 = AE(x)
u0 = sin(pi*x);
% --------------------------------------------------------------
function [pl,ql,pr,qr] = RE(xl,ul,xr,ur,t)
% Dirichlet-RE:t  
pl = ul;
ql = 0;                  % Vasemmassa reunassa 0-RE
pr = ur-abs(sin(pi*t));  % Oikeassa reunassa u=abs(sin(pi*t))
qr = 0;