codex/pressure-taps-hidden-variation.py

pressure-taps-hidden-variation.py
"""A smooth pressure variation invisible to five regularly spaced taps.
Python 3.14, NumPy 2.3.5, Matplotlib 3.10.7; writes PNG to cwd.
"""
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

x = np.linspace(0, 1, 4001)
p = -400*np.sin(4*np.pi*x)**2
samples = np.linspace(0, 1, 5)
assert np.max(abs(-400*np.sin(4*np.pi*samples)**2)) < 1e-20
assert abs(np.trapezoid(p,x) + 200) < 1e-9
fig, ax = plt.subplots(figsize=(7.6, 3.8), dpi=100, facecolor='white')
ax.plot(x,p,color='#246991',lw=2,label='Possible unsampled variation')
ax.fill_between(x,p,0,color='#246991',alpha=.14)
ax.plot(x,np.zeros_like(x),'--',color='#ad5d18',lw=1.5,label='Straight interpolation of readings')
ax.scatter(samples,np.zeros(5),s=35,color='black',zorder=4,label='Five exact tap readings')
ax.set(xlim=(-.02,1.02),ylim=(-450,200),xlabel='Chordwise coordinate x/c',ylabel='Pressure relative to reference (Pa)',title='Exact tap readings need not determine the pressure integral')
ax.set_xticks(samples)
ax.text(.5,-435,'Mean variation = −200 Pa; every sampled value = 0 Pa',ha='center',fontsize=10)
ax.spines[['top','right']].set_visible(False)
ax.grid(alpha=.13)
ax.legend(loc='upper center',bbox_to_anchor=(.5,1.02),fontsize=9)
fig.text(.5,.025,'Constructed sampling counterexample, not an airfoil measurement or flow solution',ha='center',fontsize=9)
fig.tight_layout(rect=(0,.07,1,1))
fig.savefig('pressure-taps-hidden-variation.png',facecolor='white',dpi=100)
plt.close(fig)