the thumbnail shows 1D implementation. 1,2,3,4,.... are the number of loops. in each loop I throw two numbers for each particle denoting their position and length. if the lines cross (star) I ignore I don't register the position( the round marks) or don't do anything with the lines. But if they don't cross then I have a counter that updates the number of times a hit happened in the particular position (the squared marks). then for each particle I have a counter that simply adds the lengths of this line to the previous total for each particle.
I do that (loops) a million, sometimes a 100 trillion times. then I normalize to the number of throws. the totals of the lines (normalized) are the energy. the numbers of hits for each positions is operated on to get the expectation values. normalized position hits are the probabilities that are similar to the ones we get from the "squaring" of the wavefunction. Without interaction the expectation value is the midpoint of the particle. But when interaction happens the expectation value moves. lets say to left in the left particle and right in the right particle. That denotes a repulsion. you can also get attraction with different logic. But more on the logic part later.
then the particles are moved to a
different distance and the operation is repeated.
Now I explain the code in more detail.
see here.
1. define variables/types
2. set the particle widths (d0,d1) , which I interpret as the Compton
wavelength, I assume lambda= h/mc the model shows (I will show why) that h=c ,
so lambda =1/m ,then I choose m to be in au hence if m=.0005485 then
lambda=1822.8885 units of length on the axis/line . more on scale later.
3. set the interval (intr), that is used as a quantity to increase the distance
between the particles after the calculation finished for certain distance.
4. start the mk loop that will increase the distance between the particle after
each iteration.
5. based on mk value set the positions of the particles, zero out some of the
variables need be. f1 is the number of hits for crossing f for not crossing.
Zero out the arrays (S[],Sy[]),that hold the hits for each position on the
axis/line.
6. next is the j loop the heart of the program, it iterates on the random throws
7. don't worry about these lines, not important
long r= rand();
double rndm=(double)r/((double)RAND_MAX);
8. calculate the start of the lines from inside of the particles and the length
of the lines shooting to the other particl all based on random numbers.
9. use if ( st1+p1 + li1 > st0+ p - li) to check if lines crossed or not.
10. if not crossed update the position hit by incrementing the counter S[] for
that position. add the random line to an accumulation counter (en). I do that
for one of the particles only. the other will be similar.
While I said I don't do anything when lines crossed but in this program I do the
same using Sy[], en1 just for information. I will talk more about it later.
11.go to 6
12. when done with j loop normalize the energy en to the numbers of throws
accepted frf = (double)f/en; //energy of the particle
13. calculate the expectation value for the position array S[] -over the width
of the particles.
edx = edx + (( n) * S[n]);
calculate how much expectation is offset from center of the particle
ex[mk] = (double)edx / ((double)f)- (0.5 * int(w*d1))+.5 ;
14. update all data in file for that separation.
15 . go to mk loop for new separation distance