你是否曾惊叹于彩虹的美丽?彩虹不仅是自然界的光学奇迹,其背后还隐藏着深刻的数学原理——Airy Function(艾里函数)。本文将带你用 Python 探索 Airy Function 的奥秘,并揭示它与彩虹之间的联系。让我们一起踏上这段充满知识与趣味的旅程吧!
一、什么是 Airy Function?
Airy Function 是一种特殊的数学函数,由英国天文学家乔治·比德尔·艾里(George Biddell Airy)在 1838 年提出。它在物理学和工程学中有广泛应用,尤其是在光学、量子力学和流体力学中。
Airy Function 的数学定义
Airy Function 是以下微分方程的解,它有两个线性独立的解,分别称为 Ai(x) 和 Bi(x)。

Airy Function 的图像
Airy Function 的图像呈现出振荡衰减的特性,类似于光波的衍射图案。
二、彩虹与 Airy Function 的关系
彩虹的形成与光的折射、反射和衍射密切相关。当阳光穿过雨滴时,光线会发生多次折射和反射,最终形成我们看到的彩虹。而 Airy Function 正是描述光波在雨滴中传播和衍射行为的数学工具。
彩虹的数学模型
- 光的折射与反射:光线进入雨滴后发生折射,随后在雨滴内部反射,最后再次折射出来。
- 衍射效应:光波的衍射现象可以用 Airy Function 来描述,它决定了彩虹的亮度和颜色分布。
三、用 Python 绘制 Airy Function 和彩虹
接下来,我们将用 Python 绘制 Airy Function 的图像,并模拟彩虹的光强分布。
1. 安装所需库
首先,确保安装了 scipy 和 matplotlib 库:
pip install scipy matplotlib2. 绘制 Airy Function
以下是绘制 Airy Function 的 Python 代码:
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import airy
# 定义 x 的范围
x = np.linspace(-15, 5, 500)
# 计算 Ai(x) 和 Bi(x)
ai, aip, bi, bip = airy(x)
# 绘制 Airy Function
plt.figure(figsize=(10, 6))
plt.plot(x, ai, label="Ai(x)", color="blue")
plt.plot(x, bi, label="Bi(x)", color="red")
plt.title("Airy Function: Ai(x) and Bi(x)")
plt.xlabel("x")
plt.ylabel("y")
plt.legend()
plt.grid(True)
plt.show()运行代码后,你将看到 Airy Function 的图像,其中蓝色曲线是 Ai(x),红色曲线是 Bi(x)。
3. 模拟彩虹的光强分布
我们可以用 Airy Function 模拟彩虹的光强分布。以下是示例代码:
# 模拟彩虹的光强分布
theta = np.linspace(0, np.pi, 500)
intensity = np.abs(ai) ** 2 # 光强与 Ai(x) 的平方成正比
# 绘制彩虹光强分布
plt.figure(figsize=(10, 6))
plt.plot(theta, intensity, color="purple", label="Rainbow Intensity")
plt.title("Rainbow Light Intensity Distribution")
plt.xlabel("Angle (radians)")
plt.ylabel("Intensity")
plt.legend()
plt.grid(True)
plt.show()运行代码后,你将看到彩虹的光强分布图,呈现出典型的振荡衰减特性。
四、Airy Function 的趣味应用
除了彩虹,Airy Function 还在许多领域有有趣的应用:
- 光学:描述激光束的传播和衍射。
- 量子力学:用于求解一维势阱中的粒子波函数。
- 流体力学:研究流体中的波动现象。
通过本文的探索,我们不仅了解了 Airy Function 的数学定义和图像,还揭示了它与彩虹之间的深刻联系。通过 Python 的代码实现,我们可以直观地看到 Airy Function 的振荡特性,并模拟彩虹的光强分布。希望这篇文章能激发你对数学和光学的兴趣!
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from scipy.special import airy
Set up the figure and axis
fig, ax = plt.subplots(figsize=(10, 6))
ax.set_xlim(-15, 5)
ax.set_ylim(-0.5, 1.0)
ax.set_title(“Airy Function Animation”, fontsize=16)
ax.set_xlabel(“x”, fontsize=14)
ax.set_ylabel(“Ai(x)”, fontsize=14)
ax.grid(True, linestyle=”–“, alpha=0.6)
Initialize the plot line
line, = ax.plot([], [], lw=2, color=”mediumslateblue”, label=”Ai(x)”)
ax.legend(loc=”upper right”)
Add a colorful background gradient for aesthetics
x_background = np.linspace(-15, 5, 500)
y_background = np.linspace(-0.5, 1.0, 500)
X, Y = np.meshgrid(x_background, y_background)
Z = np.sin(X) * np.cos(Y) # Arbitrary function for gradient effect
ax.imshow(Z, extent=[-15, 5, -0.5, 1.0], origin=”lower”, cmap=”viridis”, alpha=0.3)
Animation initialization function
def init():
line.set_data([], [])
return line,
Animation update function
def update(frame):
x = np.linspace(-15, frame, 500) # Gradually increase the x-range
ai, , , _ = airy(x) # Compute Ai(x)
line.set_data(x, ai)
return line,
Create the animation
ani = FuncAnimation(
fig, update, frames=np.linspace(-15, 5, 100), init_func=init, blit=True, interval=50
)
Save the animation as a GIF (optional)
ani.save(“airy_function_animation.gif”, writer=”pillow”, fps=20)
Show the animation
plt.show()
你是否曾观察过彩虹的细节?或者你对 Airy Function 的其他应用感兴趣?欢迎在评论区分享你的想法和问题

