4.0
4.0 | 1 rating Rate this file 29 Downloads (last 30 days) File Size: 5.08 KB File ID: #46576 Version: 1.1

radialDistribution2D.m

by

adi (view profile)

 

11 May 2014 (Updated )

calculates radial Distribution in 2D

| Watch this File

File Information
Description

input:
% ~~~~~~
% switchVal - operation of the finction
% initialize=0;
% sample=1;
% results=2;
% plot = 3;
%
% gR - the output struct contaning the histogram
% (shuold be created with "gR = struct;" before initialization
%
% coords - x,y coordinates of partical centers
% first row x, second row y
%
% Lx - x size of area to calculate
% Ly - y size of area to calculate
%
% NumOfBins - number of bins in the final histogram
%
% output:
% ~~~~~~~
% gR is a histogram struct contaning:
% gR.count - total number of object counted
% gR.range - x axis range for the histogram
% gR.increment - increment of x axis
% gR.saveFileName - name of saved dat file
%
% method:
% ~~~~~~~
% the RDF is calculated by binnig all pair partical distances into
% a histogram, and normalizing each bin with it's Ideal gas number of
% particals.
% when binning the pair distances, we take into acount Periodic
% Boudary Conditions (PBC)
% finaly, to ansure that when r->infinity : RDF ->1 , we
% normalize by multiplying RDF*2/(N-1) where N is the number of
% particals.
% for more information http://www2.msm.ctw.utwente.nl/sluding/TEACHING/APiE_Script_v2011.pdf
% page 48 - "Radial distribution function"
      
      -------
    |important|
      -------
      this function uses the functions "histogram", "distPBC2D"
      "histogram" can be found here: http://www.cchem.berkeley.edu/chem195/histogram_8m.html#aedd379efd57ae78820ad8787bfab0cce
     "distPBC2D" can be found here: http://www.mathworks.com/matlabcentral/fileexchange/46575-distpbc2d-m
%% example %%
example for the code above. please note that "radialDistribution2D" uses the functions "histogram" and "distPBC2D":
"histogram" can be found here: http://www.cchem.berkeley.edu/chem195/histogram_8m.html#aedd379efd57ae78820ad8787bfab0cce
"distPBC2D" can be found here: http://www.mathworks.com/matlabcentral/fileexchange/46575-distpbc2d-m

make sure these functions are in your path before you run this code.

coords = [rand(1,100); rand(1,100)]; % in this example we will calculate
% the RDF for a random sett of 100 coordinates. first row is x coordinates,
% second row is y coordinates.

Lx = 1; % board size
Ly = 1;

NumOfBins = 100; % How many bins you want in your RDF histogram. this is
% the RDF's resolution.

gR = struct; % create a struct, this is where our RDF
%(radial distribution function) will be at the end of this calculation.

% initialize gR struct
gR = radialDistribution2D(0,gR,coords,Lx,Ly,NumOfBins);

% Loop over pairs and determine the distribution of distances
gR = radialDistribution2D(1,gR,coords,Lx,Ly,NumOfBins);

% Normalize distance distribution histogram to get the RDF
gR = radialDistribution2D(2,gR,coords,Lx,Ly,NumOfBins);

% plot Result
gR = radialDistribution2D(3,gR,coords,Lx,Ly,NumOfBins);

your results are saved in "gR" struct. "gR.values" has the bins (x axis) of the RDF. "gR.histo" has the histogram (y axis) of the RDF.

MATLAB release MATLAB 8.2 (R2013b)
MATLAB Search Path
/
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
22 Aug 2015 adi

adi (view profile)

to Cesar Garcia:

If you run this code according to my example in the other comment, you can plot the RDF with:

gR = radialDistribution2D(3,gR,coords,Lx,Ly,NumOfBins);

or, you can excess the x axis of the RDF in gR.values, and the y axis of the RDF in gR.histo

Comment only
21 Aug 2015 adi

adi (view profile)

Hi, this is an example for the code above. please note that "radialDistribution2D" uses the functions "histogram" and "distPBC2D":
"histogram" can be found here: http://www.cchem.berkeley.edu/chem195/histogram_8m.html#aedd379efd57ae78820ad8787bfab0cce
"distPBC2D" can be found here: http://www.mathworks.com/matlabcentral/fileexchange/46575-distpbc2d-m

make sure these functions are in your path before you run this code.

coords = [rand(1,100); rand(1,100)]; % in this example we will calculate
% the RDF for a random sett of 100 coordinates. first row is x coordinates,
% second row is y coordinates.

Lx = 1; % board size
Ly = 1;

NumOfBins = 100; % How many bins you want in your RDF histogram. this is
% the RDF's resolution.

gR = struct; % create a struct, this is where our RDF
%(radial distribution function) will be at the end of this calculation.

% initialize gR struct
gR = radialDistribution2D(0,gR,coords,Lx,Ly,NumOfBins);

% Loop over pairs and determine the distribution of distances
gR = radialDistribution2D(1,gR,coords,Lx,Ly,NumOfBins);

% Normalize distance distribution histogram to get the RDF
gR = radialDistribution2D(2,gR,coords,Lx,Ly,NumOfBins);

% plot Result
gR = radialDistribution2D(3,gR,coords,Lx,Ly,NumOfBins);

your results are saved in "gR" struct. "gR.values" has the bins (x axis) of the RDF. "gR.histo" has the histogram (y axis) of the RDF.

Comment only
19 Feb 2015 Emil Hovad

hey Adi
I am trying to run the script, but Matlab says that gR.values is empty and where do you fill gR.value in the code. Properly i have misunderstod something, first time a have seen the rdf function.

Comment only
16 Nov 2014 Cesar Garcia

Hi, thank you for the code. I have a question related with it. How can i make to plot the RDF gotten by the code, i´m having problems to run the code. I'll appreciate all your help.
Best Regards

Updates
12 May 2014 1.1

just changed the description

22 Aug 2015 1.1

added an example to the discription

Contact us