# Using Mathematica Confirm Bessel's Inequality

I am working on the following Fourier series problem

f[x_] = Which[-1 < x < 0, 0, 0 < x < 1, x^2]
Plot[f[x], {x, -1, 1}]

a[n_] := (2/L)*Integrate[f[x]*Cos[2 n*Pi*x/L], {x, -L/2, L/2}]
a[0] := (1/L)*Integrate[f[x], {x, -L/2, L/2}]
b[n_] := (2/L)*Integrate[f[x]*Sin[2 n*Pi*x/L], {x, -L/2, L/2}]
F[x_, N_] :=
a[0] + Sum[a[n]*Cos[2 n*Pi*x/L] + b[n]*Sin[2 n*Pi*x/L], {n, 1, N}]
p[N_, a_] :=
Plot[Evaluate[F[x, N]], {x, -a, a}, PlotRange -> All,
PlotPoints -> 200]
L = 2;
f[x_] = If[x > 0, x^2, 0];
a[n]
a[0]
b[n]
Simplify[%, n \[Element] Integers]
Table[F[0.1, k], {k, 0, 20}]
p[20, 1]

My question is how can I confirm Bessel's Inequality on Mathematica :

$$\frac{a_0^2}{2}+\sum_{n=1}^{\infty}(a_n^2+b_n^2)\leq \int_{-L}^{L} f^2(x) \,dx$$ where $$a_n,b_n$$ are the coefficients of the Fourier series of the piecewise continuous function on the interval $$[-L,L]$$

## 1 Answer

One of the functions were not properly defined: $$f(x)$$

Fixing that you can create Bessels inequality in Wolfram Language:

(a[0]^2)/2 + Sum[(a[n]^2 + b[n]^2), {n, 1, Infinity}] <= Integrate[f[x]^2, {x, -L, L}]

This should work as long as the summation in WL can be reduced to a number. However, I haven't looked into if that is true.