Bernoulli's principle: finding flow speed from a pressure gauge reading, in JavaScript

2026-11-28来源 dev.toEnglish

You cannot stick a speedometer directly into a pipe of flowing water, but you can read two pressure gauges — one where the pipe is wide, one where it narrows — and Bernoulli's equation turns that pressure difference straight into a flow speed, using nothing but the two pipe areas.

The formula

For incompressible, steady flow through a horizontal pipe that narrows from area A₁ to A₂:

  • Continuity: A₁v₁ = A₂v₂
  • Bernoulli: P₁ + ½ρv₁² = P₂ + ½ρv₂²

Combining the two to eliminate v₁ gives the speed at the narrow section directly from the pressure drop:

v₂ = √( 2ΔP / (ρ (1 − (A₂/A₁)²)) )

Checked in JavaScript

const rho = 1000; // kg/m3, water const A1 = 0.02, A2 = 0.01; // m2, wide and narrow sections const dP = 5000; // Pa, pressure difference measured by the two gauges const ratio = A2 / A1; const v2 = Math.sqrt((2 * dP) / (rho * (1 - ratio * ratio))); const v1 = ratio * v2; const Q = A2 * v2; console.log(v1.toFixed(3), v2.toFixed(3), (Q * 1000).toFixed(2)); // 1.826 3.651 36.51 (v1 m/s, v2 m/s, flow rate in L/s) 

A 5000 Pa pressure drop across a pipe that narrows from 0.02 m² to 0.01 m² means the water is moving at 1.826 m/s in the wide section and 3.651 m/s in the narrow one — exactly double, because continuity forces v to scale inversely with area, and here the area halved. The flow rate works out to 36.51 litres per second either way (A₁v₁ and A₂v₂ must agree, that's the whole point of continuity).

Why the pressure drops where the pipe narrows

This is the famous, slightly counter-intuitive part of Bernoulli's principle: speeding up costs kinetic energy, and in a horizontal pipe with no height change, that energy has to come from somewhere — it comes out of the pressure. Faster-moving fluid has lower pressure, not higher, which is the opposite of what most people expect before they see the equation.

Common mistake

A frequent error is to use the difference of areas instead of their ratio in the formula, or to forget that ΔP must be positive in the direction of narrowing for the square root to make sense — the pressure is higher in the wide section and lower in the narrow one, never the other way round for flow in this direction.

Practise it online

PractiSci's Bernoulli/Venturi lab lets you change the pipe's narrow-section area and watch both the flow speed and the Venturi gauge reading update together: Bernoulli and Venturi flow lab. The Mechanical Properties of Fluids topic guide has more worked examples.

Full disclosure: I build PractiSci, a free virtual physics and chemistry lab for Class 11–12.

原文:https://www.a8q9.cn/en/article/bernoulli-s-principle-finding-flow-speed-from-a-pressure-gauge-reading-in-javasc-1ad9c3.html

相关文章