How to compute a Fourier series?

117 Views Asked by At

Consider the Fourier series

$$u(x,t)=\sum_{n=0}^\infty \frac{1}{n^2}e^{-n^2\pi^2t}\cos( n\pi x).$$

How can it be written in python (or other programming languages) to compute $u(x,t)$ as a function of $x$ or $t$?

1

There are 1 best solutions below

0
On BEST ANSWER

Hint: In Python, you can discretize the function by defining $x_k = \frac{k}{N}\Delta x$, similarly you would discretize the $t$ variable in an interval $[0,T]$, then create a matrix with entries

$$A_{p, n}=\frac{1}{n^2}e^{-n^2\pi^2 t_p} \qquad n\in [0, N)$$

and use one of the functions in Scipy's fast Fourier transform module.