Plotting outputs from for loops in a 3D space
Mostrar comentarios más antiguos
So, I managed to get a simple function to work approximately the way that I wanted, which was to take a point in 3 dimensional space, described by a vectors (x,y,z) and ascribe forces to it, based on its proximity to other points ( in this case, fixed points) described by vectors. The code is as follows.
%particle vector [x,y,z] position
pm= [1;1;1];
%particle mass, arbitrary metric
mm1=2.5;
%inital velocity of particle
vm0=[.00001;-.0000003;.000006];
%initial acceleration of particle
am0=[-.00001;.00005;-.000002];
%two forces, respectively defined by proximity to two points [5,5,5] and [-3,-3,-3]
f1= .00000006*(pm - ([5;5;5])).^2;
f2= (.0000006*(1./(pm-[-3;-3;-3]).^2));
%acceleration of particle based on the previous two forces
am= am0+(f1+f2)./mm1;
%a for loop that iteratively calculates new positions based on the previous
%values, with respect to the time variable
for t=1:.01:100
pm= ((am*(t.^2))./2)+(vm0*t)+pm
plot(pm)
end
I want to display the progression of my particle, its trajectory, in a 3D plot. How would I go about this?
Also, I would like to be able to generalize this to 'n' particles, all starting at various positions (only interacting with [5,5,5] and [-3,-3,-3], not each other). Does anyone have any thoughts on how that could be achieved elegantly? Again, I'd like to be able to visualize the trajectories of these particles as well.
I appreciate any and all help.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!