JSFiddle - React, Tailwind, and code Playground

HTML

<pre id="output"></pre>

CoffeeScript

potentialCube = ([x0,y0,z0], a, n) ->
	potential = 0.0
	da = a/n
	arr = ( (t-0.5)*da for t in [1..n])
	for x in arr 
		for y in arr
			for z in arr
				[dx,dy,dz] = [x-x0,y-y0,z-z0]
				potential += 1.0/Math.sqrt(dx*dx + dy*dy + dz*dz)
	potential * da*da*da

sqrt3 = Math.sqrt 3

forceCubeAtVertice = (a,n,d) ->
	( potentialCube([ d,0,0],a,n) - potentialCube([ 0,0,0],a,n) ) / d *sqrt3
    

a = 1.0
force0 = 1.6790293517162

output = document.getElementById("output")
output.innerHTML = [10,100,200].reduce( (out,n) ->
    force = forceCubeAtVertice a, n, a/n/100
    error = 100*(force-force0)/force0
    out + """
	n = #{n}
	force = #{force}
	error = #{error.toFixed 3} %
	------------------------------\n"""
, "")