-
Notifications
You must be signed in to change notification settings - Fork 22
/
fisher.m
51 lines (40 loc) · 1.79 KB
/
fisher.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
50
51
function fisher
%FISHER Displays solutions to Fisher PDE.
m = 0; a = -50; b = 50; t0 = 0; tf = 20;
xvals = linspace(a,b,101); tvals = linspace(t0,tf,51);
[xmesh, tmesh] = meshgrid(xvals,tvals);
figure(1), subplot(2,2,1), sol = pdepe(m,@fpde,@fica,@fbc,xvals,tvals);
ua = sol(:,:,1); mesh(xmesh,tmesh,ua)
xlabel('x'), ylabel('t'), zlabel('u','Rotation',0), title('u(x,t)')
text_set, view(30,30)
subplot(2,2,2), contour(xmesh,tmesh,ua,[0.2:0.2:0.8])
xlabel('x'), ylabel('t','Rotation',0), title('Contour Plot')
text_set, hold on, txt = {'Ref. slope = 2','FontSize',8};
plot([10,20,20,10],[8,13,8,8],'r--'), text(0,6,txt{:}), hold off
subplot(2,2,3), sol = pdepe(m,@fpde,@ficb,@fbc,xvals,tvals);
ub = sol(:,:,1); mesh(xmesh,tmesh,ub)
xlabel('x'), ylabel('t'), zlabel('u','Rotation',0), title('u(x,t)')
text_set, view(30,30)
subplot(2,2,4), contour(xmesh,tmesh,ub,[0.2:0.2:0.8])
xlabel('x'), ylabel('t','Rotation',0), title('Contour Plot')
text_set, hold on
plot([25,35,35,25],[5,10,5,5],'r--'), text(11,3,txt{:}), hold off
figure(2), zmesh = xmesh - 2*diag(tvals)*ones(size(xmesh));
waterfall(zmesh,tmesh,ua)
xlabel('x-2t'), ylabel('t'), zlabel('u','Rotation',0), title('u(x-2t,t)')
zlim([0 1]), text_set, view(15,30)
%-------------------------- Local functions ------------------------------%
function [c,f,s] = fpde(x,t,u,DuDx)
%FDE Fisher PDE.
c = 1; f = DuDx; s = u*(1-u);
function u0 = fica(x)
%FIC Fisher initial condition: 1st case.
u0 = 0.99*(x<=-20);
function [pa,qa,pb,qb] = fbc(xa,ua,xb,ub,t)
%FBC Fisher boundary conditions.
pa = 0; qa = 1; pb = 0; qb = 1;
function u0 = ficb(x)
%FIC2 Fisher initial condition: 2nd case.
u0 = 0.25*(cos(0.1*pi*x).^2).*(abs(x)<=5);
function text_set
h = findall(gca,'type','text'); set(h,'FontSize',12,'FontWeight','bold')