Wednesday
October 1, 2014

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

Computer Science - MATLAB - In a problem I had to create a animation of the ...
Thank You MathMate - Thank you for assisting me with my MATLAB question. If I ...
pre calc trig check my work please - sin x + cos x -------------- = ? sin x sin ...
algebra - Can someone please help me do this problem? That would be great! ...
Computer Science - MATLAB - thanks mathmate. It's way above my head to. I got ...
math - find all solutions in the interval [0,2 pi) sin(x+(3.14/3) + sin(x- 3.14/...
tigonometry - expres the following as sums and differences of sines or cosines ...
trig!! - Sin(X-y)sin(x+y)=sin^2 x - sin^2 y work on one side only...so i worked ...
Trig - Sin(X-y)sin(x+y)=sin^2 x - sin^2 y work on one side only...so i worked on...
TRIG! - Posted by hayden on Monday, February 23, 2009 at 4:05pm. sin^6 x + cos^6...

Search
Members