MatLab Animation Problem

  • Thread starter MacLaddy
  • Start date
  • #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:

Answers and Replies

Related Threads on MatLab Animation Problem

  • Last Post
Replies
5
Views
2K
  • Last Post
Replies
0
Views
1K
  • Last Post
Replies
6
Views
595
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
0
Views
3K
Replies
4
Views
1K
  • Last Post
Replies
1
Views
1K
Replies
3
Views
1K
Replies
0
Views
3K
Top