Contents
Deep Breakdown
What it tells me (Situation Awareness): The antiderivative of sine is negative cosine. The negation comes from the derivative relationship: . The factor comes from the chain rule when the argument is affine . In DA/DS, sine integrals appear in Fourier analysis (computing Fourier coefficients requires integrating ), signal processing (band-pass filter energy calculation), modeling seasonal patterns (integrating sinusoidal revenue or demand models), and physics-informed ML (integrating oscillatory features in neural network inputs). Any model with cyclical features of the form will require this formula when computing expected values or total accumulations.
Flowchart
Real-world use
Where it is used
Fourier series: coefficients require integrating . Seasonal demand modeling: total demand over a period when demand follows (yearly seasonality). Energy of an oscillating signal: (uses ).
Problem it solves
Integrating oscillatory functions analytically gives exact results without numerical approximation errors. This matters in Fourier decomposition where numerical integration of many coefficients would accumulate errors.
How it solves the problem
Use the antiderivative chain: , so . The antiderivative of is thus .
Example in a business
A retail chain models weekly foot traffic as (visitors per day, in days). Total visitors in the first 14 days: . The sine integral evaluates to (two full cycles cancel). Total = 7,000 visitors, exactly the mean times the period.
The formula, piece by piece
Each symbol:
- : the integrand, oscillating between and
- : the negation comes from the derivative relationship
- : chain rule compensation for the inner derivative of
- : the cosine of the same argument; the integral shifts from sine to cosine
- : constant of integration Special cases:
- :
- : (angular frequency)
The formula in words
"The antiderivative of is the negative of , divided by the coefficient of (the chain rule factor). The switch from sine to cosine and the negation come from the derivative cycle: ."
Critical Concepts
- Trig derivative cycle: . Integration reverses: .
- Chain rule compensation: the is always present when the argument is instead of .
- Integral over full period is zero: because evaluated at start and end of a full period equals the same value.
- Power of sine: (uses trig identity, not directly this formula).
- Fourier coefficient: for (orthogonality), for (derived using this formula).
Step-by-step calculation (tiny example)
Compute and .
Step 1: Identify a and b For : , .
Step 2: Apply the formula .
Step 3: Verify by differentiating
Step 4: Evaluate the definite integral
Code examples
Beginner example (Python)
import numpy as np
from scipy import integrate
def sin_antiderivative(x: float, a: float, b: float) -> float:
"""F(x) = -(1/a)*cos(ax+b). Requires a != 0."""
if abs(a) < 1e-12:
raise ValueError("a = 0: integrand is constant sin(b).")
return -(1.0 / a) * np.cos(a * x + b)
def sin_definite(lo: float, hi: float, a: float, b: float) -> float:
return sin_antiderivative(hi, a, b) - sin_antiderivative(lo, a, b) # Test cases
cases = [ (0.0, np.pi, 1.0, 0.0), # int sin(x) from 0 to pi = 2
(0.0, np.pi/2, 2.0, 0.0), # int sin(2x) from 0 to pi/2 = 1
(0.0, 2*np.pi, 1.0, 0.0), # full cycle = 0
]
for lo, hi, a, b in cases:
analytic = sin_definite(lo, hi, a, b)
numerical, _ = integrate.quad(lambda x, aa=a, bb=b: np.sin(aa*x+bb), lo, hi)
print(f"int_({lo:.3f},{hi:.3f}) sin({a}x+{b}): " f"analytic={analytic:.6f}, numerical={numerical:.6f}, " f"match={abs(analytic-numerical)<1e-8}")Beginner example (R)
sin_antiderivative <- function(x, a, b) { if (abs(a) < 1e-12) stop("a = 0.") -(1 / a) * cos(a * x + b)
}
sin_definite <- function(lo, hi, a, b) { sin_antiderivative(hi, a, b) - sin_antiderivative(lo, a, b)
}
cases <- list(c(0, pi, 1, 0), c(0, pi/2, 2, 0), c(0, 2*pi, 1, 0))
for (tc in cases) { lo <- tc[1]; hi <- tc[2]; a <- tc[3]; b <- tc[4]
analytic <- sin_definite(lo, hi, a, b)
numerical <- integrate(function(x) sin(a*x+b), lower=lo, upper=hi)$value
cat(sprintf("int_(%5.3f,%5.3f) sin(%gx+%g): analytic=% .6f, num=% .6f, match=%s\n", lo, hi, a, b, analytic, numerical, isTRUE(all.equal(analytic, numerical, tol=1e-7))))
}Professional example (Python)
"""
Fourier sine coefficients
for seasonal demand decomposition. Monthly demand follows:
D(t) = trend(t) + sum_k [b_k * sin(k*omega*t)]
where
omega = 2*pi/12 (annual period). Fourier sine
coefficient: b_k = (2/T) * int_0^T
D(t) * sin(k*omega*t) dt For a known
D(t), this integral evaluates using the sine antiderivative
formula, applying integration by parts when
D(t) is polynomial. We demonstrate: fit synthetic seasonal demand with sine components,
then recover coefficients analytically and numerically.
"""
import numpy as np
from scipy import integrate # Synthetic monthly demand (2 years = 24 months)
OMEGA = 2.0 * np.pi / 12.0 # annual frequency
T_FULL = 24.0
def true_demand(t: np.ndarray) -> np.ndarray:
"""True model: 1000 + 200*sin(omega*t) + 80*sin(2*omega*t)."""
return 1000.0 + 200.0 * np.sin(OMEGA * t) + 80.0 * np.sin(2 * OMEGA * t)
def fourier_sin_coefficient(demand_fn: object, k: int, period: float = 12.0) -> float:
""" b_k = (2/T) * int_0^T f(t) * sin(k*omega*t) dt Computed numerically (analytic would use sine formula + IBP). """
omega = 2.0 * np.pi / period
result, _ = integrate.quad( lambda t: demand_fn(t) * np.sin(k * omega * t), 0, period )
return 2.0 / period * result # Recover coefficients
print("=== Fourier Sine Decomposition of Seasonal Demand ===")
print(f"True model: D(t) = 1000 + 200*sin(omega*t) + 80*sin(2*omega*t)")
print()
for k in range(1, 5):
b_k = fourier_sin_coefficient(true_demand, k, period=12.0)
print(f"b_{k} = {b_k:+.4f} (expected: b_1=200, b_2=80, rest=0)") # Demonstrate: integral of pure sine over integer multiple of
periods = 0
print("\n=== Orthogonality verification ===")
for k in range(1, 4):
full_cycle_integral, _ = integrate.quad( lambda t: np.sin(k * OMEGA * t), 0, 12.0 ) # Analytic: [-(1/(k*omega)) * cos(k*omega*t)]_0^12 = 0 (full period) print(f"int_0^12 sin({k}*omega*t) dt = {full_cycle_integral:.10f} (should be ~0)")Source: 1300 p. 245