Code:
[p,e,t]=initmesh('squareg');
x=p(1,:);
y=p(2,:);
u0=atan(cos(pi/2*x)); % Initial Condition
ut0=3*sin(pi*x).*exp(sin(pi/2*y)); % Initial Condition
n=500; % List of times
tlist=linspace(0,5,n); % Generates a row vector tlist of n points linearly spaced between and including a and b
uu=hyperbolic(u0,ut0,tlist,'squareb3',p,e,t,1,0,0,1); % Squareb3 is boundary conditions
delta=-1:0.1:1;
[uxy,tn,a2,a3]=tri2grid(p,t,uu(:,1),delta,delta);
gp=[tn;a2;a3];
umax=max(max(uu));
umin=min(min(uu));
newplot
M=moviein(n);
for i=1:n,
pdeplot(p,e,t,'xydata',uu(:,i),'zdata',uu(:,i), ...
'mesh','on','xygrid','on','gridparam',gp,...
'colorbar','off','zstyle','discontinuous');
axis([-1 1 -1 1 umin umax]);...
caxis([umin umax]);
M(:,i)=getframe;
end
This code uses the 'hyperbolic' command (line 8 of the code) to define the wave equation.