home *** CD-ROM | disk | FTP | other *** search
- %VIBES Movie of the vibrating L-shaped membrane.
- echo off
- % C. B. Moler, 6-30-91, 8-27-92.
- % Copyright (c) 1984-93 by The MathWorks, Inc.
-
- clf
- drawnow
- echo on
- clc
-
- % 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.
-
- echo off
-
- % Load eigenfunction data.
- load vibesdat
- n = max(size(L1));
- nh = fix(n/2);
- x = (-nh:nh)/nh;
- clf
- contour(x,x,L1,18), prism
- disp('Press any key to proceed ...')
- pause
-
- % Get coefficients from eigenfunctions.
- clear c
- for k = 1:12
- eval(['c(k) = L' num2str(k) '(24,13)/3;'])
- end
-
- % Set graphics parameters.
- clf
- axis([-1 1 -1 1 -1 1]);
- caxis(26.9*[-1.5 1]);
- colormap(hot);
- format compact
- hold on
-
- % Generate the movie.
- delt = 0.1;
- nframes = 12;
- M = moviein(nframes);
- for k = 1:nframes
- disp(k)
-
- % 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);
-
- % Capture the frame
- M(:,k) = getframe;
- end
- hold off
-
- echo on
-
- % Now the movie can be played back at roughly 12 frames per second.
-
- movie(M,20,12);
-
- echo off
-
- % Push buttons
-
- callback = [ ...
- 'set(uip,''back'',[1 2/3 1/3]);' ...
- 'movie(M,20,12); ' ...
- 'set(uip,''back'',''default'');' ];
- uip = uicontrol('style','push','pos',[20 10 60 40],'string','Replay', ...
- 'call',callback);
- uiq = uicontrol('style','push','pos',[100 10 60 40],'string','Done', ...
- 'call','clf; ');
-