Borrar filtros
Borrar filtros

Timed plots of Particle-in-a-box?

1 visualización (últimos 30 días)
Cas Cas
Cas Cas el 27 de Oct. de 2017
I am writing some particle-in-a-box code and have it working just fine. However, I'm wondering if it is possible to time it so that perhaps it goes down from crest to trough in 2 seconds and then back up from trough to crest in 6. I tried working it out myself but I'm a bit stuck with the timings.
% Constants and variables
n = 1;
Lx = 1;
hbar = 1;
m = 1;
k = @(n) n*pi/Lx;
w = hbar*k(n)^2/2*m;
A = sqrt(2/Lx)./2;
x = linspace(0,Lx,200);
fs = 44100;
total = 6;
ratio = 0.2;
down = total/(ratio + 1);
up = total - down;
% t = linspace(0,total,500);
t = linspace(0,total,fs*total);
% Position and time functions
psi = @(x,n) A.*sin(k(n)*x);
phi = @(t) exp(-1i.*w.*t);
% Plot it.
for ii = 1:up*fs/60:up*fs
% if m<= (up/2)*fs
figure(1)
cla
plot(x, real(psi(x,n)*phi(t(ii))))
xlim([0 1])
ylim([-1.5 1.5])
drawnow
end
for m = up*fs:down*fs/60:total*fs
figure(1)
cla
plot(x, real(psi(x,n)*phi(t(m))))
xlim([0 1])
ylim([-1.5 1.5])
drawnow
% pause(0.2)
end
I used the drawnow method because I want to eventually grab the frames and make a movie. I tried to make an attempt at calculating when the ups and downs end and doing something like "if we're still going down, then go at this speed else go up at this other speed". I also tried to use the pause command but it's been tricky. Thanks in advance.

Respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by