# Using numerical integration to calculate Fourier series' coefficients

I am using Fourier series to find the analytical solution to the 2D heat equation. The problem is that the integrals which are used to calculate the coefficients of the series cannot be solved analytically.

I am currently using GSL's Monte Carlo integration to compute them an this introduces error to the series. My question is will the solution converge to the analytical solution or not? If not, How can I get an estimate of the error?

EDIT

This is my initial condition:

\begin{align} &C_0(x,y) = \left\lbrace \begin{array}{lll} 0 & &r(x,y) \geq 15\\ 4- \dfrac{4}{15} r(x,y) & &r(x,y) < 15 \end{array}\right. \label{ch3-diffusion-2d-circle-init-cond}\\ &r(x,y) = \sqrt{(x-75)^2 + (y-50)^2} \end{align}

and this is the integral:

$$A_{mn}={4\over l_x l_y}\int_0^{l_y} \int_0^{l_x} C_0(x,y)\sin\left({m\pi\, x\over l_x}\right)\sin\left({n\pi\, y\over l_y}\right)\,dx\,dy, \quad \forall m,n \in \aleph$$

where $l_x=l_y = 100$.

This is what I get after 500 iterations:

Which hasn't really improved from iteration 100.

• What is the thing being plotted? There are no axis labels, and it's not clear from context what iteration means. Fourier integrals can sometimes be rewritten as (here) discrete sine transforms, and computed with FFT. – Kirill Sep 12 '15 at 17:00
• @Kirill, This is the $C_0(x,y)$'s plot. By 500 iterations I meant the sums go up to 500 instead if infinity. – Eliad Sep 12 '15 at 21:48

The quadrature formula you should be using depends on the structure of the integrand, i.e., in your case $\int f(x) \sin(kx) \; dx$. For example, if $f(x)$ is smooth, then using a high order Gaussian integration scheme is likely appropriate. If $f(x)$ is discontinuous, then Gauss formulas are not appropriate, but they may be on the individual segments were $f(x)$ is smooth. Without more information about the integrand you have, it is not possible to provide a better answer.