-
Notifications
You must be signed in to change notification settings - Fork 0
/
p35.m
22 lines (22 loc) · 882 Bytes
/
p35.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
% p35.m - Allen-Cahn eq. as in p34.m, but with boundary condition
% imposed explicitly ("method (II)")
% Differentiation matrix and initial data:
N = 20; [D,x] = cheb(N); D2 = D^2;
eps = 0.01; dt = min([.01,50*N^(-4)/eps]);
t = 0; v = .53*x + .47*sin(-1.5*pi*x);
% Solve PDE by Euler formula and plot results:
tmax = 100; tplot = 2; nplots = round(tmax/tplot);
plotgap = round(tplot/dt); dt = tplot/plotgap;
xx = -1:.025:1; vv = polyval(polyfit(x,v,N),xx);
plotdata = [vv; zeros(nplots,length(xx))]; tdata = t;
for i = 1:nplots
for n = 1:plotgap
t = t+dt; v = v + dt*(eps*D2*v + v - v.^3); % Euler
v(1) = 1 + sin(t/5)^2; v(end) = -1; % BC
end
vv = polyval(polyfit(x,v,N),xx);
plotdata(i+1,:) = vv; tdata = [tdata; t];
end
clf, subplot('position',[.1 .4 .8 .5])
mesh(xx,tdata,plotdata), grid on, axis([-1 1 0 tmax -1 2]),
view(-60,55), colormap([0 0 0]), xlabel x, ylabel t, zlabel u