%VIBES	Movie of the vibrating L-shaped membrane.

%	C. B. Moler, 6-30-91, 8-27-92.
%	Expo demo adapted by Ned Gulley, 6-21-93
%	Copyright (c) 1984-94 by The MathWorks, Inc.

% Demo initialization
if ~exist('MovieGUIFlag'), figNumber=0; end;

hlpStr= ...                                                
        [' This movie animates a solution of the wave       '  
         ' equation for the vibrations of an L-shaped       '  
         ' membrane.  The solution is expressed as a        '  
         ' linear combination, with time-dependent          '  
         ' coefficients, of two-dimensional spatial         '  
         ' eigenfunctions. The eigenfunctions have been     '  
         ' pre-computed using the function MEMBRANE,        '  
         ' and saved in a file. The first of these          '  
         ' eigenfunctions, the fundamental mode, is the     '  
         ' MathWorks logo.                                  '  
         '                                                  '  
         ' The L-shaped geometry is of particular interest  '  
         ' mathematically because the stresses approach     '  
         ' infinity near the reentrant corner. Conventional '  
         ' finite difference and finite element methods     '  
         ' require considerable time and storage to         '  
         ' achieve reasonable accuracy. The approach        '  
         ' used here employs Bessel functions with          '  
         ' fractional order to match the corner singularity.'];
mvinit(figNumber,hlpStr);

% This demonstration solves the wave equation for the vibrations
% of an L-shaped membrane.  The solution is expressed as a linear
% combination, with time-dependent coefficients, of two-dimensional
% spatial eigenfunctions.  The eigenfunctions have been pre-computed,
% using the function MEMBRANE, and saved in a file.  The first of
% these eigenfunctions, the fundamental mode, is the MathWorks logo.
%
% The L-shaped geometry is of particular interest mathematically because
% the stresses approach infinity near the reentrant corner.  Conventional
% finite difference and finite element methods require considerable
% time and storage to achieve reasonable accuracy.  The approach used
% here employs Bessel functions with fractional order to match the
% corner singularity.
%
% As the solution is computed and displayed at each of 12 time steps,
% snapshots of the graphics window are saved in a large matrix.
% The total storage required is proportional to the area of the graphics
% window.  About 2 megabytes is required for the default window.

% Now make the movie
% Load eigenfunction data.
load vibesdat
n = max(size(L1));
nh = fix(n/2);
x = (-nh:nh)/nh;

% Get coefficients from eigenfunctions.
clear c
for k = 1:12
   	eval(['c(k) = L' num2str(k) '(24,13)/3;'])
end
 
% Set graphics parameters.
axis([-1 1 -1 1 -1 1]);
caxis(26.9*[-1.5 1]);
colormap(hot);
hold on

% Generate the movie.
delt = 0.1;
nframes = 12;
M = moviein(nframes);
for k = 1:nframes,
    % Coefficients
    t = k*delt;
    s = c.*sin(sqrt(lambda)*t);

    % Amplitude
    L = s(1)*L1 + s(2)*L2 + s(3)*L3 + s(4)*L4 + s(5)*L5 + s(6)*L6 + ...
       	s(7)*L7 + s(8)*L8 + s(9)*L9 + s(10)*L10 + s(11)*L11 + s(12)*L12;

    % Velocity
    s = s .* lambda;
    V = s(1)*L1 + s(2)*L2 + s(3)*L3 + s(4)*L4 + s(5)*L5 + s(6)*L6 + ...
    	s(7)*L7 + s(8)*L8 + s(9)*L9 + s(10)*L10 + s(11)*L11 + s(12)*L12;

    % Surface plot of height, colored by velocity.
    % Cut out the reentrant corner
    V(1:nh,1:nh) = NaN*ones(nh,nh);
    cla
    surf(x,x,L,V);
    axis off

    % Capture the frame
    M(:,k) = mvframe(figNumber,nframes);
end;
hold off
%====================================
% Store the movie
mvstore(figNumber,M);
