Sample JAVA program of hydrogen molecule - average values.

Top page (correct Bohr model including helium).
Back to hydrogen molecule page.

If you copy and paste the program source code below into a text editor, you can easily compile and run this.
(This class file name is avera, so save this text editor as "avera.java", and compile it.)
Here we use the new unit of 1 MM = 1 × 10-14 meter.

In this program, first we input the internuclear distance (in MM ) of H2.
And then input y-coordinate "r" (in MM) , and x-coordinate "a" ( in MM ) of electron 1.
From the inputted values, this program outputs the binding energy (eV) of H2, total force acting on nucleus 1 (nucforce), x,y components of forces acting on electron 1 (= elefx, elefy ).
These forces are expressed as the ratio to the force between electron and nucleus of H atom's ground state.

From the force acting on electron and its velocity, we calculate the number of de Broglie wave in one orbit.
( Here Virial theorem E = -T = 1/2 V is used. )
"another x" means another x coordinate of electron 1 moving in the direction of force.
And then we do above calculation again when x-coordinate is another x.
avebinding means average binding energies ( x is "a" and "another x" ), avewave means average de Broglie waves ( x is "a" and "another x" ).
The initial x-coodinate is automatically increased per calculation until +100.


import java.util.Scanner;
class calcu 
  {

    double me=9.1093826e-31; 
    double pai=3.141592653589793; 
    double epsi=8.85418781787346e-12;
    double h=6.62606896e-34; 
    double ele=1.60217653e-19; 
    double boh=5292.0*5292.0*1.0e-28;  // boh = ( Bohr radius )^2 
    double a,r,nuc,rra,binding,elefx,elefy,wave,nucforce, anotherx;

   void disp( ) {

   double ke=(ele*ele)/(4.0*pai*epsi);
   double rra=Math.sqrt(a*a+r*r);       // rra =distance between electron 1 and n1
   double rrb=Math.sqrt(r*r+(nuc-a)*(nuc-a));  // rrb=  between electron 1 and n2
   double rrc=Math.sqrt(4*r*r+(nuc-2*a)*(nuc-2*a)); // between two electrons
 
   double poten=ke*(-2.0/rra-2.0/rrb+1.0/nuc+1.0/rrc);  // poten=potential energy (J)
   double ppot=poten*6.241509e18;       // ppot = potential energy (eV) 
                                  
   double kinetic=-0.5*poten;       // kinetic = total kinetic energy of two electrons (J)
   double velo=Math.sqrt(kinetic/me);  // velo = electron's velocity (m/s) 
   binding=-ppot*0.5-13.606*2;          // binding energy (eV) of H2

                            // foeces acting on electron 1 ( x, -y directions )
   elefx= -a/(rra*rra*rra) + (nuc-a)/(rrb*rrb*rrb) - (nuc-2*a)/(rrc*rrc*rrc);
   elefy= r/(rra*rra*rra) + r/(rrb*rrb*rrb) - (2*r)/(rrc*rrc*rrc);
   double eleforce = ke*Math.sqrt(elefx*elefx + elefy*elefy);  // total force

   double radius=(me*velo*velo)/eleforce; // rotation radius from centrifugal force
   double debroglie = h/(me*velo);       // de Broglie wavelength of electron
   wave=(2*pai*radius)/debroglie;  // wave's number in one orbit

   nucforce= a/(rra*rra*rra)-1.0/(nuc*nuc)+(nuc-a)/(rrb*rrb*rrb);
   nucforce=nucforce * boh;            // total force acting on nucleus 1

   anotherx=a+(2.0*r*elefx)/elefy; 
   anotherx = anotherx * 1.0e14;       // another x coordinate of electron 1

    elefx=elefx * boh; elefy = elefy * boh;

    }}

 class avera
  {
    public static void main(String[] args) {
 
    Scanner stdIn=new Scanner(System.in);   
    System.out.println(" Internuclear distance (MM) of H2 molecule ?  ");  
    double nnuc=stdIn.nextDouble(); 

    System.out.println(" r (MM)? = y coodinate of electron 1 ");  
    double rr=stdIn.nextDouble();

    System.out.println(" a (MM) ? = x coodinate of electron 1 ");  
    double aa=stdIn.nextDouble(); 
 
    calcu c;
    c = new calcu();

    c.r=rr*1.0e-14; c.nuc=nnuc*1.0e-14;    // change MM to meter
    

   for (int i=1;i < 10;i++){            // repeat calculation from a to a + 10*10 (MM)
   
   
     c.a=aa*1.0e-14;
     c.disp();                   // to void disp calculation

  
   System.out.printf("a:%.1f ", aa);
   System.out.printf(" binding: %.4f ", c.binding); 
   System.out.printf(" elefx: %.3f ", c.elefx);
   System.out.printf(" elefy: %.3f ", c.elefy);
   System.out.printf("nucforce: %.3f \n", c.nucforce);
   System.out.printf(" another x : %.2f ", c.anotherx);
   System.out.printf(" wave: %.4f ", c.wave);

   double wwave = c.wave; 
   double bbind = c.binding;      
   c.a=c.anotherx*1.0e-14;        // repeat calculation above when a = another x
   c.disp();
   
                              // average binding energy and waves ( "a" and "another x" )
   bbind = ( c.binding + bbind )/2.0; wwave = (c.wave+wwave)/2.0;
   System.out.printf(" avebinding: %.4f ", bbind); 
   System.out.printf(" avewave: %.4f \n", wwave);
   System.out.printf("                        \n");

  aa=aa+10;}}}