Sunday
April 20, 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 ...
math - Eliminate the parameter (What does that mean?) and write a rectangular ...
math - Use the exact values of the sin, cos and tan of pi/3 and pi/6, and the ...
Math(Please help) - 2) Use the sum and difference identites sin[x + pi/4] + sin[...
Math(Please help) - 1)tan Q = -3/4 Find cosQ -3^2 + 4^2 = x^2 9+16 = sqrt 25 = 5...
math - find all solutions in the interval [0,2 pi) sin(x+(3.14/3) + sin(x- 3.14/...
Pre-Cal - Find the 5 roots of x^5+1=0 in polar and Cartesian form. (x^5 means x ...
trig - Give exact answers Sin(11pi/8) so this is sin(pi/4+pi/3) sin(pi/4)*cos(pi...
math - Use the exact values of the sin, cos and tan of pi/3 and pi/6, and the ...
d/dx - d/dx( ln |sin(pi/x)| ) = ? Thanks. If those are absolute value signs, the...

Search
Members