Hi everyone,
I'm trying to simulate the positions of a number of molecules in free space over time, occasionally being hit by helium atoms (random velocity) and photons (uniform velocity). I have it set up to work through a number of steps, each time changing the velocity of the particular molecule based on a helium kick and then a photon kick. It then creates a position array, of dimensions (#molecules, 3, #steps). Those mechanics all seem to work. My problem comes when trying to plot the position over time. I'd like to plot each molecule's [x,y,z] position coordinate across the total number of steps, but the code below returns some sort of strange triangular graph in three dimensions that I'm not sure how to interpret. When I had this code set up for one dimension, it worked just fine.
So is there a way to plot an individual row of each "page" of the 3d array across the total number of steps?
numParticles = 10;numSteps = 100;HeliumThreshold = 0.1;PhotonThreshold = .49999;PhotonKick = [.0005193164, 0, 0];Sigmav = .000005193164*eye(3);v = zeros(numParticles, 3, numSteps);x = zeros(numParticles, 3, numSteps);for stepNumber = 2 : numSteps for p = 1 : numParticles HeliumProb = rand; PhotonProb = rand; Deltav = [0, 0, 0; 0, 0, 0]; if HeliumProb > HeliumThreshold HeliumKick = mvnrnd([0, 0, 0], Sigmav, 1); Deltav(1, :) = HeliumKick; else Deltav = Deltav; end if PhotonProb > PhotonThreshold Deltav(2, :) = HeliumKick + PhotonKick; else Deltav = Deltav; end v(p, :, stepNumber) = v(p, :, stepNumber - 1) + Deltav(2, :); x(p, :, stepNumber) = x(p, :, stepNumber - 1) + v(p, :, stepNumber); X=reshape(x,[],3); plot3(X(:,1),X(:,2),X(:,3)); hold on end hold offend
Also, here's a picture of the plot:
Best Answer