function fourier_coefficients(f) {
let sine_coefficients;
let cosine_coefficients;
if (type == 'full') {
sine_coefficients = d3
.range(N)
.map(
n =>
int(
x => f(x) * Math.sin((n * Math.PI * x) / L),
-L,
L,
1e-10,
10,
5
) / L
);
cosine_coefficients = d3
.range(N)
.map(
n =>
int(
x => f(x) * Math.cos((n * Math.PI * x) / L),
-L,
L,
1e-10,
10,
5
) / L
);
cosine_coefficients[0] = cosine_coefficients[0] / 2;
} else if (type == 'sine') {
sine_coefficients = d3
.range(N)
.map(
n =>
int(
x => 2 * f(x) * Math.sin((n * Math.PI * x) / L),
0,
L,
1e-10,
10,
5
) / L
);
cosine_coefficients = Array.from({ length: N }, x => 0);
} else if (type == 'cosine') {
cosine_coefficients = d3
.range(N)
.map(
n =>
int(
x => 2 * f(x) * Math.cos((n * Math.PI * x) / L),
0,
L,
1e-10,
10,
5
) / L
);
cosine_coefficients[0] = cosine_coefficients[0] / 2;
sine_coefficients = Array.from({ length: N }, x => 0);
}
return {
sine_coefficients: sine_coefficients,
cosine_coefficients: cosine_coefficients
};
}