1

I need to create a script that will calculate the overlap orbital of two 1s orbitals. The integral is given by

Integral

I tried calculating this using code but my answer is nowhere near the analytic result of S=(1+R+R^2/3)exp(-R). Could someone help me figure where I went wrong?

The code:

import Foundation

var sum: Double = 0.0 //The integral result
var step_size: Double = 0.0000025
var a: Double = 0.0
var R: Double = 5.0
var next_point: Double = 0.0
var midpoint: Double = 0.0
var height: Double = 0.0
var r_val: Double = 0.0

func psi_func(r_val: Double) -> Double {

    return exp(-r_val)
}

//Integration

while next_point < R {

    next_point = a + step_size
    midpoint = a + step_size/2
    height = psi_func(r_val: midpoint)
    sum += psi_func(r_val: midpoint)*step_size

    a = a + step_size

}

print("S = ", 2*3.14159*3.14159*sum) // This is a 3-D orbital, so I multiply by 2*pi*pi

For R = 5.0

My answer: 19.61

Analytic answer: 0.097

Alistra
  • 5,177
  • 2
  • 30
  • 42
loltospoon
  • 239
  • 1
  • 9

1 Answers1

0

Two problems I can see:

  1. I see a single wavefunction and not the product of two in your code
  2. It is incorrect to just do a 1d integral and multiply by 2pi^2 in the end

Try doing a proper 3d integral with the correct integrand.

Raziman T V
  • 480
  • 1
  • 4
  • 12