Borrar filtros
Borrar filtros

Cumulative radial distribution of particle centers

10 visualizaciones (últimos 30 días)
yu sh
yu sh el 30 de Mzo. de 2016
Comentada: Fahad Obaid el 18 de Mzo. de 2020
Hi, I have just started working with Matlab. Need some help to initiate my following task.
I want to find out the cumulative radial distribution of particle centers by drawing spheres of radius 'R'. Initially the value of radius 'R' will be zero and it will increment with a value 'delta R' in each step. In each step the program should calculate the number of particle centers falling inside the sphere and it will terminate when all the given particle centers covered. In the end I want the code to plot a graph between 'reduced radial distance from centers vs Included particles'
I have particle centers in 3D and also their radius as they are itself considered as spheres. The starting point for the sphere of radius 'R' is the geometric center of the system which I also need to calculate.
  2 comentarios
Image Analyst
Image Analyst el 30 de Mzo. de 2016
Are the particles themselves spheres? So that you have a bunch of spheres of increasing radius? And you place each new sphere such that it does not overlap/intersect existing spheres, so that you need to keep getting/testing random locations until the new sphere would fit? And then you want to find how how many individual small spheres are in a bigger containing sphere of radius "R"?
yu sh
yu sh el 30 de Mzo. de 2016
Editada: yu sh el 30 de Mzo. de 2016
Yes the particles are spheres but their radii are fixed they are not increasing, they are located at different points I just know their center coordinate and individual radii. I will draw a sphere with geometric center of the system as its center and increment that particular sphere and check how many particle centers (existing spheres with fixed radii) are falling inside them until all of them included

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Mzo. de 2016
See if this simulation does what you want:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Make 99,000 spheres in a cube 100 by 100 by 100
numParticles = 99000;
x = 100 * rand(1, numParticles);
y = 100 * rand(1, numParticles);
z = 100 * rand(1, numParticles);
% Find the center of all of these
xCentroid = mean(x);
yCentroid = mean(y);
zCentroid = mean(z);
% Find the distances of all the particles from the centroid
distances = sort(sqrt((x - xCentroid).^2+(y - yCentroid).^2+(z - zCentroid).^2));
% Get a distribution (count) of how many particles are at each distance
subplot(2, 1, 1);
histObj = histogram(distances)
grid on;
title('Histogram', 'FontSize', fontSize);
xlabel('Distance', 'FontSize', fontSize);
ylabel('Count', 'FontSize', fontSize);
% Compute the count within a radius by computing the CDF
cdf = cumsum(histObj.Values);
radius = histObj.BinEdges(1:end-1);
subplot(2, 1, 2);
plot(radius, cdf, 'b-', 'LineWidth', 2);
grid on;
title('CDF, Cumulative Distribution Function', 'FontSize', fontSize);
xlabel('Radius (Distance from centroid)', 'FontSize', fontSize);
ylabel('Number Within that Radius', 'FontSize', fontSize);
  7 comentarios
AB
AB el 31 de Ag. de 2017
Hello,
This is a great post. I have a follow up question as I am trying to do something very similar.
If I have different data sets for my problem but all of them have different no. of spherical particles. How can I normalize them and plot them on the same graph? Can I use fraction of spherical particles in the CDF graph? If yes, how to do that? Any other suggestions will also be appreciated
Thanks!
Fahad Obaid
Fahad Obaid el 18 de Mzo. de 2020
Hello,
I am working on finding the radial distribution function. My question is how I plot the code that written by (Image Analyst) as the curve shown in the link https://en.wikibooks.org/wiki/Molecular_Simulation/Radial_Distribution_Functions#/media/File:Simulated_Radial_Distribution_Functions_for_Solid,_Liquid,_and_Gaseous_Argon.svg
I need to plot the curve instead of the histogram I really appreciate your help.

Iniciar sesión para comentar.

Más respuestas (1)

John D'Errico
John D'Errico el 30 de Mzo. de 2016
You are looking at this the wrong way. First, NEVER reinvent the wheel. Use existing, high quality code written by professionals before stepping in and writing your own, especially if you are a novice to programming. Otherwise, you will find yourself overwhelmed with the complexities of dealing with a poorly written, inefficient code.
You are looking for a histogram, or perhaps a cumulative histogram. There are tools for this already written.
Just compute the set of distances from the origin, then call the appropriate histogram tool. I honestly can't recall if there is a cumhist tool in MATLAB. I think so, but it is easily cobbled from hist itself anyway, and I won't have access to MATLAB for the next day or so. A google search for cumhist did show MATLAB code.

Community Treasure Hunt

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

Start Hunting!

Translated by