Multiple 3d random walks
    12 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    lena kappa
 el 8 de Dic. de 2022
  
    
    
    
    
    Comentada: lena kappa
 el 8 de Dic. de 2022
            Hi everyone I have the next code that creates a 3d random walk but i would like to have in the 3d space some random points(seeds) and start from each one of them a random walk at the same time. Can anyone help me?? My code for the random walk is the following: 
lamda = 3; %Mean free path 
numberOfSteps = 100000; % Totlal number of steps 
x(1) = rand; % Initial position (x) 
y(1) = rand; % Initial position (y) 
z(1) = rand; % Initial position (z)
for i = 1:numberOfSteps
    r = -lamda*log(rand());  % Distance Travelled
    theta = pi*rand();       % Arbritary angle in between 0 and Pi
    phi = 2*pi*rand();       % Arbritary angle in between 0 and 2Pi
    dx = r*sin(theta)*cos(phi);   % Step Size (x)
    dy = r*sin(theta)*sin(phi);   % Step Size (y)
    dz = r*cos(theta);            % Step Size (z)
    x(i+1) = x(i) + dx;  % Position at the end of the first step (x)
    y(i+1) = y(i) + dy;  % Position at the end of the second step (y)
    z(i+1) = z(i) + dz;  % Position at the end of the third step (z)
end
plot3(x, y, z, 'k');
0 comentarios
Respuesta aceptada
  Torsten
      
      
 el 8 de Dic. de 2022
        
      Editada: Torsten
      
      
 el 8 de Dic. de 2022
  
      lambda = 3; %Mean free path 
numberOfSteps = 10000; % Total number of steps 
numberOfPaths = 3; % Number of paths
x(1,:) = rand(1,numberOfPaths); % Initial position (x) 
y(1,:) = rand(1,numberOfPaths); % Initial position (y) 
z(1,:) = rand(1,numberOfPaths); % Initial position (z)
for j = 1:numberOfPaths
  for i = 1:numberOfSteps
    r = -lambda*log(rand());  % Distance Travelled
    theta = pi*rand();       % Arbritary angle in between 0 and Pi
    phi = 2*pi*rand();       % Arbritary angle in between 0 and 2Pi
    dx = r*sin(theta)*cos(phi);   % Step Size (x)
    dy = r*sin(theta)*sin(phi);   % Step Size (y)
    dz = r*cos(theta);            % Step Size (z)
    x(i+1,j) = x(i,j) + dx;  % Position at the end of the first step (x)
    y(i+1,j) = y(i,j) + dy;  % Position at the end of the second step (y)
    z(i+1,j) = z(i,j) + dz;  % Position at the end of the third step (z)
  end
end
plot3(x(:,1), y(:,1), z(:,1), 'k');
hold on
plot3(x(:,2), y(:,2), z(:,2), 'r');
plot3(x(:,3), y(:,3), z(:,3), 'g');
hold off
3 comentarios
  Torsten
      
      
 el 8 de Dic. de 2022
				Sorry, I don't know.
Maybe you should open a separate question for this.
Más respuestas (0)
Ver también
Categorías
				Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



