I'm trying to implement a triple integral Riemann sum. My single and double integral codes are working. I just added the for k in range (1,l+1):, l = int(zb/dz) and za+(k-1)*dz in the code below. It's not getting any error nor results. It's just running. It's been more than an hour now. What other ways/code would you suggest as a replacement of the code below? Using math library only and has to implement the function calculate(f, xa, xb, ya, yb, za, zb). I'm still new to this just for your information. Thank you for all the help.
dx = 0.002
dy = 0.002
dz = 0.002
def calculate(f, xa, xb, ya, yb, za, zb):
n = int(xb/dx)
m = int(yb/dy)
l = int(zb/dz)
t = dx*dy*dz
total = 0
for i in range (1,n+1):
for j in range (1,m+1):
for k in range (1,l+1):
total += f(xa+(i-1)*dx, ya+(j-1)*dy, za+(k-1)*dz)*t
return total
def p(x, y, z):
return math.sin(x) + math.cos(y) + math.tan(z)
s = calculate(p, 0, 3, 0, 2, 0, 1)
print("{:.3f}".format(s))
