Thursday
August 27, 2015

Homework Help: Computer Science - MATLAB

Posted by Lee on Wednesday, July 20, 2011 at 2:59am.

Thanks MathMate. Print plotting sounds awful O_O. What you suggested was correct and this code worked

disp('Problem 13.9')
x=[-2*pi:.00001*pi:2*pi];
a=0;
y=sin(x-a);
g=plot(x,y);
title(sprintf('sin(x-%.2f)\n',a))
grid on;
set(g,'EraseMode','xor')
while a<=8*pi
a=a+.1*pi;
y=sin(x-a);
plot(x,y)
title(fprintf('sin(x-%.2f)\n',a))
grid on;
drawnow
end

I have another question though that I seem to be struggling with.

Create an animation of the following:

Let x vary form -2pi to +2pi
Let y=sin(x)
Let z=sin(x-a)cos(y-a)

Let a be the animation variable.
Remember that you'll need to mesh x and y to create two-dimensional matrices; use the resulting arrays to find z.

Here's my attempt at a solution.

x=-2*pi:pi/50:2*pi;
y=sin(x);
[X,Y]=meshgrid(x,y);
z=sin(X)*cos(Y);
h=surf(z);
axis tight
set(gca,'nextplot','replacechildren');
shading interp
colormap(jet)
for a=0:pi/100:8*pi
z=sin(X-a)*cos(Y-a);
set(h,'zdata',z);
drawnow
end

When I try to run it the axes are colored for like a tenth of a second and then it just turns to white. I don't know exactly what I'm doing wrong.

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

More Related Questions

Members