

% The following code serves to produce animated graphs for the 
% normal modes of vibration of a vibrating membrane.

%  Data
    L=1;
    H=1;
    Nt=250;             % Maximum # of time iterations.
    NN=100;             % Number of points in the x-direction
    M=100;              % Number of points in the y-direction
    deltat=0.01
    deltax=L/NN
    deltay=H/M
    m=1;                % These two paremeters "m" and "n" serve to identify the mode
    n=2;
    c=1;
    sqrtlnm= sqrt((n*pi/L)^2+(m*pi/H)^2);   % Eigenvalue
  
% Generating the grid in the xy-plane. Two arrays.
    for i=1:NN+1
        for j=1:M+1
            x(i,j)= (i-1)*deltax;
            y(i,j)=(j-1)*deltay;
        end
    end
    
 % Loop in time where the surfaces are created
    for nt=1:Nt
        t=(nt-1)*deltat;
        for i=1:NN+1
            for j=1:M+1
                u(i,j)= cos(c*sqrtlnm*t)*sin(n*pi/L*x(i,j))*sin(m*pi/H*y(i,j));
            end
        end
        surf(x,y,u);
        axis([0 1 0 1 -1 1]);
        xlabel('x-axis');
        ylabel('y-axis')
        view(-63,10);               % You can change these view by rotating your surface and identifying new locations.
%        pause
%       pause(0.1);
        pause(0.00001)  % The animation is produced by introducing this pause. It's that simple!
    end