-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPDE_MATLAB_deas.m
49 lines (40 loc) · 1.02 KB
/
PDE_MATLAB_deas.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%% Intro
%This is a demo of the basic pde-solving capabilities of MATLAB. This does
%not include the more robust (and involved) capabilities included in the
%PDE toolbox.
%In general, pdepe expects a PDE of the form:
% c(x,t,u,du/dx)*du/dt = x^{-m}*d/dx(x^m * f(x,t,u,du/dx)) + s(x,t,u,du/dx)
% For example, the diffusion equation is: du/dt = d^2u/dx^2
% So, c=1, m=0, f=du/dx and s=0
% An advection term can be added by changing s
%% Mesh
L = 1;
x = linspace(0,L,100);
t = linspace(0,0.5,1000);
%% Solve Equation
m = 0;
sol = pdepe(m,@heatpde,@heatic,@heatbc,x,t);
%% Plot
figure
colormap hot
pcolor(x,t,sol)
shading('flat')
colorbar
xlabel('Distance x','interpreter','latex')
ylabel('Time t','interpreter','latex')
title('PDE for $0 \le x \le 1$ and $0 \le t \le 5$','interpreter','latex')
%% Functions
function [c,f,s] = heatpde(x,t,u,dudx)
c = 1;
f = dudx;
s = 0;%-5*dudx;
end
function u0 = heatic(x)
u0 = 0.5;
end
function [pl,ql,pr,qr] = heatbc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = ur - 1;
qr = 0;
end