Wednesday
May 22, 2013

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

Thank You MathMate - Thank you for assisting me with my MATLAB question. If I ...
computer - A-Asking the user to pick a number between 1 and 20 and having the ...
Computer Science - MATLAB - Create a stacked contour plot of the MRI data, ...
Computer Science - MATLAB - In a problem I had to create a animation of the ...
Computer Science - MATLAB - thanks mathmate. It's way above my head to. I ...
programming - Week 3 - Expand Pseudo Code The accounting office indicated the ...
computer science - write a program to select the classes that you are taking(Ex...
Ethics and the Administration of Justice - Please Help!!!· In previous ...
computer science - ineed help with c++. i am using code blocks and i have a ...
Math - Hi I have optimization Qs with MATLAB can you help me and did you know ...

For Further Reading

Search
Members
Community