- #1

MacLaddy

Gold Member

- 291

- 11

## Homework Statement

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

## Homework Equations

## 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');

%shading interp

%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: