Exercise 4.1
Vectorized PVT Calculations
A reservoir engineer needs the oil formation volume factor at a range of reservoir pressures. Below the bubble point, rises as pressure drops because gas comes out of solution and the remaining oil expands. Above the bubble point, the oil is undersaturated and stays roughly constant.
A simplified correlation:
Use vectorised NumPy (no Python for loops) to compute at every pressure in one expression.
Given:
pressures = np.array([1500, 2000, 2500, 3000, 3500])
P_b = 2500Store the result as a NumPy array bo with the same shape as pressures.
Stuck? Reveal hints one at a time — they progress from nudge to near-solution.
visibilityReveal reference solutionexpand_more
Try solving it yourself first — the hints walk you through it. The solution below is one valid approach; yours may differ and still be correct.
import numpy as np
pressures = np.array([1500, 2000, 2500, 3000, 3500])
P_b = 2500
bo = np.where(pressures <= P_b, 1.0 + 0.00012 * (P_b - pressures), 1.0)
print(bo)
lockCopying code is a Full Access feature.