# An Introduction to the Mathematical Theory of Waves

### Roger Knobel (view profile)

20 Aug 2002 (Updated )

Companion Software

wvslice(action,myFunction,min_t,max_t,min_x,max_x)
```function wvslice(action,myFunction,min_t,max_t,min_x,max_x)
%wvslice  Plot cross-section slices of a surface u=u(x,t)
%
%        <DESCRIPTION>
%        wvslice is a graphical interface which displays cross-sections of
%        of a surface u=u(x,t) in xtu-space at discrete times t.
%
%        <TO RUN>
%        Type wvslice at the MATLAB prompt with no arguments.
%
%        <USE>
%        After startup, set any of the following controls:
%
%          Time t     - Interval t0 < t < t1 to plot u=u(x,t)
%          Range x    - Interval x0 < x < x1 to plot u=u(x,t)
%          View Point - View xtu-space from and angle PHI rotated up/down from
%                       the xt-plane and angle THETA rotated around
%                       the u axis in the xt-plane.
%          Number of Cuts - Number of discrete times tn in the interval
%                           t0 < t < t1 at which to plot the curve u(x,t), x0<x<x1.
%          u(x,t)  -  Field in which to define the function u(x,t)
%
%        After setup, press the REDRAW button to render the slice plot.
%
%        Use the OTHER VIEWS menu to pass the current control parameters
%        to ANIMATE (wvmovie) or view the full surface SURFACE PLOT (wvsurf).

% Created: 6/95 by R. Knobel
% Requires: MATLAB 4.2(c) - MATLAB 5.2
% Also links to: wvmovie.m and wvslice.m

if nargin < 1
action = 'start';
end

if ~strcmp(action,'start'),
handles=get(gcf,'UserData');
hTmin = handles(1);
hTmax = handles(2);
hXmin = handles(3);
hXmax = handles(4);
hCuts = handles(5);
hFunction = handles(6);
hAxes = handles(7);
hPhi  = handles(8);
hTheta = handles(9);
end;

if strcmp(action,'start'),

bgcolor = 'black';
fgcolor = 'white';

figure;
set(gcf, ...
'NumberTitle','off', ...
'Name','Surface Slice', ...
'BackingStore','off',...
'Units','normalized',...
'Color',bgcolor);

% Console Frame

top      =0.95;
bottom   =0.10;
left     =0.82;
btnWid   =0.13;
btnHt    =0.06;
spacing  =0.02;
frmBorder=0.02;

frmPos=[left-frmBorder bottom-frmBorder btnWid+3*frmBorder ...
top-bottom+2*frmBorder];
uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position', frmPos, ...
'ForegroundColor',fgcolor,...
'BackgroundColor',bgcolor);

%  Time interval

uicontrol( ...
'Style','text',...
'Units','normalized',...
'Position', [.81 .905 .15 .04],...
'BackgroundColor',bgcolor,...
'ForegroundColor','red',...
'String','Time t');

uicontrol( 'Style','text',...
'Units','normalized',...
'Position', [.81 .86 .08 .04],...
'BackgroundColor',bgcolor,...
'ForegroundColor',fgcolor,...
'String','Initial');
if nargin < 3,
min_t = 0;
end;
hTmin=uicontrol( ...
'Style','edit',...
'Units','normalized',...
'Position', [.89 .86 .07 .04],...
'BackgroundColor','white',...
'ForegroundColor','black',...
'String',num2str(min_t));

uicontrol( 'Style','text',...
'Units','normalized',...
'Position', [.81 .81 .08 .04],...
'BackgroundColor',bgcolor,...
'ForegroundColor',fgcolor,...
'String','Final');
if nargin < 4,
max_t = 3;
end;
hTmax=uicontrol( ...
'Style','edit',...
'Units','normalized',...
'Position', [.89 .81 .07 .04],...
'BackgroundColor','white',...
'ForegroundColor','black',...
'String',num2str(max_t));

% X interval

uicontrol( ...
'Style','text',...
'Units','normalized',...
'Position', [.81 .73 .15 .04],...
'BackgroundColor',bgcolor,...
'ForegroundColor','red',...
'String','Range x');

uicontrol( 'Style','text',...
'Units','normalized',...
'Position', [.81 .68 .06 .04],...
'BackgroundColor',bgcolor,...
'ForegroundColor',fgcolor,...
'String','Min');
if nargin < 5,
min_x = 0;
end;
hXmin=uicontrol( ...
'Style','edit',...
'Units','normalized',...
'Position', [.87 .68 .09 .04],...
'BackgroundColor','white',...
'ForegroundColor','black',...
'String',num2str(min_x));

uicontrol( 'Style','text',...
'Units','normalized',...
'Position', [.81 .63 .06 .04],...
'BackgroundColor',bgcolor,...
'ForegroundColor',fgcolor,...
'String','Max');
if nargin < 6,
max_x = 5;
end;
hXmax=uicontrol( ...
'Style','edit',...
'Units','normalized',...
'Position', [.87 .63 .09 .04],...
'BackgroundColor','white',...
'ForegroundColor','black',...
'String',num2str(max_x));

% View

uicontrol( ...
'Style','text',...
'Units','normalized',...
'Position', [.81 .55 .15 .04],...
'BackgroundColor',bgcolor,...
'ForegroundColor','red',...
'String','View Point');

uicontrol( 'Style','text',...
'Units','normalized',...
'Position', [.81 .50 .08 .04],...
'BackgroundColor',bgcolor,...
'ForegroundColor',fgcolor,...
'String','Phi');
phi = 30;
hPhi=uicontrol( ...
'Style','edit',...
'Units','normalized',...
'Position', [.89 .50 .07 .04],...
'BackgroundColor','white',...
'ForegroundColor','black',...
'String',num2str(phi));

uicontrol( 'Style','text',...
'Units','normalized',...
'Position', [.81 .45 .08 .04],...
'BackgroundColor',bgcolor,...
'ForegroundColor',fgcolor,...
'String','Theta');
theta = 30;
hTheta=uicontrol( ...
'Style','edit',...
'Units','normalized',...
'Position', [.89 .45 .07 .04],...
'BackgroundColor','white',...
'ForegroundColor','black',...
'String',num2str(theta));

% Number of slices

uicontrol(...
'Style','text',...
'Units','normalized',...
'Position',[.81 .37 .15 .05],...
'BackgroundColor',bgcolor,...
'ForegroundColor','red',...
'String','# of Cuts');
num_cuts = 10;
hCuts=uicontrol( ...
'Style','edit',...
'Units','normalized',...
'Position', [.85 .32 .06 .05],...
'BackgroundColor','white',...
'ForegroundColor','black',...
'String',num2str(num_cuts));

% The Redraw and Close Buttons

uicontrol( ...
'Style','push', ...
'Units','normalized', ...
'Position',[left bottom+btnHt+spacing  btnWid btnHt], ...
'String','Redraw', ...
'Callback','wvslice(''restart'')');

uicontrol('Style','Pushbutton', ...
'Units','normalized',...
'Position',[left bottom btnWid btnHt], ...
'Callback','wvslice(''close'')',...
'String','Close');

% Function field

if nargin < 2,
myFunction = 'exp(-(x-t)^2)';
end;

uicontrol('Style','text',...
'Units','normalized',...
'Position',[.03 .02 .10 .05],...
'BackgroundColor',bgcolor,...
'ForegroundColor',fgcolor,...
'String','u(x,t) = ');
hFunction=uicontrol(...
'Style','edit',...
'Units','normalized',...
'Position',[.13 .02 .6 .05],...
'BackgroundColor','white',...
'ForegroundColor','black',...
'String',myFunction );

% Menu for calling other 3D visualization tools

'Label','Surface Plot',...
'CallBack','wvslice(''GotoSurface'')');
'Label','Animate',...
'CallBack','wvslice(''GotoAnimate'')');

% Set up plot area

hAxes = axes('Position',[.12 .28 .6 .6],...
'XLim',[min_x max_x],...
'YLim',[min_t max_t],...
'ZLim',[0     1    ],...
'Color',bgcolor,...
'XColor',fgcolor,...
'YColor',fgcolor,...
'ZColor',fgcolor);
hold on;
view(phi,theta);
xlabel('x');
ylabel('t');
zlabel('u');

handles=[hTmin hTmax hXmin hXmax hCuts hFunction hAxes hPhi hTheta];
set(gcf,'UserData',handles);

wvslice('restart')

elseif strcmp(action,'restart'),

cla

f = get(hFunction,'String');
l = length(f);
for k = fliplr(find((f=='^') | (f=='*') | (f=='/')))
if ~strcmp(f(k-1),'.')
f = [f(1:k-1) '.' f(k:l)];
l = l+1;
end
end
vectorized_f = f;

min_x    = str2num(get(hXmin,'String'));
max_x    = str2num(get(hXmax,'String'));
num_cuts = str2num(get(hCuts,'String'));
min_t    = str2num(get(hTmin,'String'));
max_t    = str2num(get(hTmax,'String'));
phi      = str2num(get(hPhi,'String'));
theta    = str2num(get(hTheta,'String'));

if num_cuts > 1,
del_t = (max_t - min_t) / (num_cuts-1);
else
num_cuts = 1;
del_t    = 0;
end;

[x,t] = meshgrid(linspace(min_x,max_x,50), ...
linspace(min_t,max_t,num_cuts) );

u     = eval(vectorized_f);
min_u = min(u(:));
max_u = max(u(:));

set(hAxes,...
'XLim',[min_x max_x],...
'YLim',[min_t max_t],...
'ZLim',[min_u max_u],...
'View',[theta phi] );

for j=1:num_cuts
X = x(j,:);
T = t(j,:);
U = u(j,:);
plot3(X,T,U,'y')
end;

elseif strcmp(action(1:4),'Goto')

myFunction = get(hFunction,'String');
min_x      = str2num(get(hXmin,'String'));
max_x      = str2num(get(hXmax,'String'));
min_t      = str2num(get(hTmin,'String'));
max_t      = str2num(get(hTmax,'String'));

wvslice('close')

if strcmp(action,'GotoAnimate'),
wvmovie('start',myFunction,min_t,max_t,min_x,max_x),
elseif strcmp(action,'GotoSurface'),
wvsurf('start',myFunction,min_t,max_t,min_x,max_x),
end;

elseif strcmp(action,'close'),

close

end
```