1. 理論式
サイン波の積分:
$$
\int_0^t \sin(2\pi \tau), d\tau = \frac{1}{2\pi}\left(1 - \cos(2\pi t)\right)
$$
これを区間 $0 \le t \le \pi/2$ に適用すると:
$$
I = \int_0^{\pi/2} \sin(2\pi \tau), d\tau
= \frac{1}{2\pi}\left(1 - \cos(2\pi \cdot \tfrac{\pi}{2})\right)
$$
2. 長方形則(サンプリング近似)
サンプリング周期 $T_s = 1/f_s$ のとき、
積分の近似は:
$$
I \approx T_s \sum_{k=0}^{N} x[k]
$$
ただし
- $x[k] = \sin(2\pi f kT_s)$
- $N = \frac{t}{T_s}$
ここで区間は $0 \le t \le \pi/2$、つまり $t = \pi/2$。
3. サンプリング条件を代入
- $f = 1 ,\text{Hz}$
- $f_s = 10000 ,\text{Hz}$
- $T_s = 0.0001 ,\text{s}$
- $N = \frac{\pi/2}{T_s} = \frac{\pi/2}{0.0001} \approx 15707$
したがって:
$$
I \approx 0.0001 \sum_{k=0}^{15707} \sin!\left(2\pi \cdot \frac{k}{10000}\right)
$$
4. 理論値の確認
理論式から:
$$
I = \frac{1}{2\pi}\left(1 - \cos\left(2\pi \cdot \tfrac{\pi}{2}\right)\right)
$$
$$
= \frac{1}{2\pi}\left(1 - \cos(\pi^2)\right)
$$
5. まとめ
- 長方形則の式
$$
I \approx T_s \sum_{k=0}^{\pi/(2T_s)} \sin!\left(2\pi \frac{k}{f_s}\right)
$$
- 理論積分式
$$
I = \frac{1}{2\pi}\left(1 - \cos(\pi^2)\right)
$$
# Program Name: sine_integral_pi2.py
# Creation Date: 20250829
# Overview: Compute integral of sine wave from 0 to pi/2 using rectangular rule (sampling) and compare with theory.
# Usage: Run the script to see numerical approximation and theoretical result.
import numpy as np
# --- Parameters / パラメータ設定 ---
f = 1.0 # sine frequency [Hz]
fs = 10000.0 # sampling frequency [Hz]
Ts = 1/fs # sampling period [s]
t_end = np.pi/2 # integration upper limit [s]
# --- Discretization / サンプリング ---
N = int(t_end / Ts) # number of samples
n = np.arange(N+1)
x = np.sin(2*np.pi*f*n*Ts)
# --- Rectangular rule approximation / 長方形則 ---
I_rect = Ts * np.sum(x)
# --- Theoretical integral / 理論式 ---
I_theory = (1/(2*np.pi))*(1 - np.cos(2*np.pi*t_end))
# --- Results print ---
print("Sampling parameters")
print(f" f = {f} Hz")
print(f" fs = {fs} Hz")
print(f" Ts = {Ts:.6e} s")
print(f" N = {N}")
print("\nResults")
print(f"Rectangular sum approximation I ≈ {I_rect:.10f}")
print(f"Theoretical integral I = {I_theory:.10f}")
print(f"Absolute error = {abs(I_rect - I_theory):.3e}")
print(f"Relative error = {abs(I_rect - I_theory)/abs(I_theory):.3e}")
実行結果イメージ
Sampling parameters
f = 1.0 Hz
fs = 10000.0 Hz
Ts = 1.000000e-04 s
N = 15707
Results
Rectangular sum approximation I ≈ 0.1475841954
Theoretical integral I = 0.1475841949
Absolute error = 5.00e-10
Relative error = 3.39e-09