# MatLab Animation Problem

1. May 5, 2013

1. The problem statement, all variables and given/known data

Create an animation of the following:

Let x vary from -2pi to 2pi
Let y = sin(x)
Let z = sin(x-theta) * cos(y-theta)

Let theta be the animation variable

remember, you will need to mesh x and y to create a two-dimensional
matrices: use the resulting arrays to find z

2. Relevant equations

3. The attempt at a solution

This is what I've tried so far, and it is following closely with an example in my book.

clear, clc, clf
X = [-2*pi:pi/50:2*pi];
theta = 0;
Y = sin(X);
[x,y] = meshgrid(X,Y);
z = (sin(x-theta) * cos(y-theta));
h = surf(z);
axis tight
set(gca,'nextplot','replacechildren');
%colormap(jet)

while theta < 4*pi;
z = sin(x-theta) * cos(y-theta);
theta = theta+(pi/50);
set(h,'ZData',z);
drawnow
end

I've been wracking my brain for a while over this, and I'm failing to see what isn't varying correctly. Any help, or a nudge in the right direction, will be appreciated.

Thanks,
Mac

Last edited: May 5, 2013