Apr-06-2022, 03:26 PM
(This post was last modified: Apr-06-2022, 04:42 PM by deanhystad.)
Why do you loop over range(1, i+1) and then subtract 1 from i?
This is not correct.
I have no idea why it would take hours. I set dz = 1 and the program takes 1.3 seconds on my computer. I set dz = 0.2 and it took 5 times longer (5.3 seconds). I set dz = 0.02 and it took 10 times longer than that (50 seconds). I would expect dz = 0.002 should take 500 seconds. A long time to wait, but not hours.
For the function p this is a particularly inefficient way to compute the total. In your particular example cos(ya+(j-1)*dy) is computed for each iteration of the "k" loop. The value is the same each time. You are calling math.cos() 500 times more often then is needed, and you are calling math.sin() 500,000 times more often than is needed.
This is not correct.
n = int(xb/dx) m = int(yb/dy) l = int(zb/dz)It is only correct if xa, ya and za are all zero.
I have no idea why it would take hours. I set dz = 1 and the program takes 1.3 seconds on my computer. I set dz = 0.2 and it took 5 times longer (5.3 seconds). I set dz = 0.02 and it took 10 times longer than that (50 seconds). I would expect dz = 0.002 should take 500 seconds. A long time to wait, but not hours.
For the function p this is a particularly inefficient way to compute the total. In your particular example cos(ya+(j-1)*dy) is computed for each iteration of the "k" loop. The value is the same each time. You are calling math.cos() 500 times more often then is needed, and you are calling math.sin() 500,000 times more often than is needed.