Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the program in Python only! The Madleung constant (Newman Exercise 2.9, p.

ID: 3750963 • Letter: W

Question

Write the program in Python only!

The Madleung constant (Newman Exercise 2.9, p.74) The Madelung constant gives the total potential felt by an atom in a solid. Consider the case of the sodium chloride crystal, which has atoms arranged on a cubic lattice, but with alternating sodium and chlorine atoms. The sodium atoms have a single positive charge +e and the chlorine atoms have a single negative charge -e, where e is the charge of the electron. If we label each position on the lattice by three integer coordinates (ij, k), then the sodium atoms fall at positions where i +j + k is even, and the chlorine atoms at positons where i +j+kis odd. Consider a sodium atom at the origin, 1 ++ k = O, and let us calculate the Madelung constant. If the spacing of the atoms on the lattice is the origin to the atom at position (i,j, k) is then the distanced from and the potential at the origin created by such an atom is with 0 being the permittivity of the vacuum and the sign of the expression depending on whether i +j + k is even or odd. The total potential felt by the sodium atom is then the sum of this quantity V(i,j,k) over all other atoms Let us assume a cubic box around the sodium at the origin, with L atoms in all directions. Then Votal V(i,j, k) = where M is the Madelung constant, or equivalently At least approximately-technically the Madelung constant is the value of M when L oo, but one can get a good approximation just by using a large value of L.) Write a program to calculate and print the Madelung constant for sodium chloride. Use as large a value of L as you can, while still having your program run in less than a minute. (Start by testing it with small values of L.)

Explanation / Answer

Here we are asked to calculate the Madelung constant for sodium chloride. The equation to find Madelung constant is already given in the question ,that is the last one.We will calculate the Madelung constant for l=100 in this program.

#!/usr/bin/python

import math

l=input("Enter vlue of l")

m=0

for i in range (1,100):

for j in range (1,100):

for k in range (1,100):

m+=1/(math.sqrt(i*i+j*j+k*k))

print "The Madelung constant is:",m

#if you want to print the vtotal we can use the equation and add that line of code also in loop. That additional statement should be added after m value calculation inside the loop.