concept average flow rate in category python

appears as: verage flow rate, average flow rate, The average flow rate, verage flow rates, average flow rates, The average flow rates
Math for Programmers: 3D graphics, machine learning, and simulations with Python MEAP V11

This is an excerpt from Manning's book Math for Programmers: 3D graphics, machine learning, and simulations with Python MEAP V11.

Our formula for average flow rate depends on the volume function V and the starting and ending times t1 and t2, which are the parameters we’ll pass to the corresponding Python function. The body of the function is a direct translation of this mathematical formula to Python:

def average_flow_rate(v,t1,t2): 
      return (v(t2) - v(t1))/(t2 - t1)

This function is simple, but important enough to walk through as an example calculation. Let’s use the volume function (plotted in figure 8.3 and included in the source code) and say we want to know the average flow rate into the tank between the 4-hour mark and the 9-hour mark. In this case, t1 = 4 and t2 = 9. To find the starting and ending volumes, we can evaluate the volume function at these times:

>>> volume(4) 
  3.3 
  >>> volume(9) 
  5.253125

Rounding for simplicity, the difference between the two volumes is 5.25 bbl − 3.3 bbl = 1.95 bbl, and the total elapsed time is 9 hr − 4 hr = 5 hr. Therefore, the average flow rate into the tank is roughly 1.95 bbl divided by 5 hr or 0.39 bbl/hr. Our function confirms we got this right:

8.1.2                   Picturing the average flow rate with a secant line

Another useful way to think about the average rate of change in volume over time is to look at the volume graph. Let’s focus on the two points on the volume graph between which we calculated the average flow rate. In figure 8.4, the points are shown as dots on the graph, and I’ve drawn a line passing through them. A line passing through two points on a graph like this is called a secant line.

Figure 8.4: A secant line connects the starting and ending points on the volume graph.

As you can see, the graph is higher at 9 hours than at 4 hours because the volume of oil in the tank increased during this period. This causes the secant line connecting the starting and ending points to slope upward. It turns out the slope of the secant tells us exactly what the average flow rate is on the time interval.

Here’s why. Given two points on a line, the slope is the change in the vertical coordinate divided by the change in the horizontal coordinate. In this case, the vertical coordinate goes from V(t1) to V(t2) for a change of V(t2) − V(t1), and the horizontal coordinate goes from t1 to t2 for a change of t2t1. The slope is then (V(t2) − V(t1)) / (t2-t1), exactly the same calculation as the average flow rate (figure 8.5)!

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest