I have a simple matlab script for calculating an Integral using trapezoidal rule.
The idea is calculate Fourier series, and it used for the Fourier coefficients.
function [area] = recArea(func, xl, xr, N, n)
if nargin < 5
n = 1;
end
w = ((xl - xr) / N);
y = eval(func);
area = sum((y(1:end-1) + y(2:end)) / 2*w);
end
Call example:
$a_n$ = recArea(func, xl, xr, N)
in the function:
function [y] = fourier(m, N, func, xl, xr)
Where:
$func$ is the function to calculate it's fourier sereis
$xl, xr$ the integral bounds: $\int_{xl}^{ar}$.
Can you please explain me how this code works?
Thanks in advance.