Cumulative radial distribution of particle centers

조회 수: 6 (최근 30일)
yu sh
yu sh 2016년 3월 30일
댓글: Fahad Obaid 2020년 3월 18일
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
Image Analyst
Image Analyst 2016년 3월 30일
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 2016년 3월 30일
편집: yu sh 2016년 3월 30일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2016년 3월 30일
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
AB
AB 2017년 8월 31일
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 2020년 3월 18일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2016년 3월 30일
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.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by