concept volume change in category python

This is an excerpt from Manning's book Math for Programmers: 3D graphics, machine learning, and simulations with Python.
We call the second function volume_change(q,t1,t2,dt) and, as the difference in naming suggests, we use it to calculate the volume change on any time interval, not just a brief one. Its arguments are the flow rate function q, a start time t1, an end time t2, and a small time interval dt. The function breaks the time interval down into increments of duration dt, which are short enough to use the brief_volume_change function. The total volume change returned is the sum of all of the volume changes on the short time intervals.
Once again, we can use the NumPy arange function to get the starting time for each of the intervals. The function call np.arange(t1,t2,dt) gives us an array of times from t1 to t2 in increments of dt. For each time value t in this array, we can find the volume change in the ensuing time interval using small_volume_change. Finally, we need to sum the results to get the total volume change over all of the intervals. This can be done in roughly one line:
def volume_change(q,t1,t2,dt): return sum(small_volume_change(q,t,dt) for t in np.arange(t1,t2,dt))With this function, we can break up the time from 0 to 10 hours into 100 time intervals of duration 0.1 hours and sum the volume changes during each. The result matches the actual volume change to one decimal place: