# Find the function $f(x)$ by using its fourier expansion

It is easy to find the fourier coefficient and fourier expansion of $f(x)$ function.

But I want solve the inverse problem by using Mathematica

How to find the function $f(x)$, if I know its fourier coefficient (or fourier expantion)?

for example:

$$a_n=\frac{1}{\pi^2n^2}$$

$$b_n=0$$

$$a_0=\frac{1}{6}$$ or

$$f(x)=\frac{1}{6}-\sum_{n=1}^{\infty}\frac{\cos2xn\pi}{(n\pi)^2}$$

I tried:

Simplify[1/6 - Sum[Cos[2 x Pi n]/(Pi n)^2, {n, 1, Infinity}]] Plot[%, {x, -3, 3},PlotRange -> 1] this is a fourier series of $f(x)=x(1-x).$ with $0 \leq x \leq 1$

but how can I get $x(1-x)$ from $\frac{1}{6}-\sum_{n=1}^{\infty}\frac{\cos2xn\pi}{(n\pi)^2}$?

or in other word,

How to solve the system of integral equations for $f(x)$ by using Mathematica?

$$\begin{cases} \int_{a}^{b}f(x)dx=conts.\\ \int_{a}^{b}f(x)\sin(n x)dx=A(n)\\ \int_{a}^{b}f(x)\cos(n x)dx=B(n) \end{cases}$$

Note that the expression returned by Sum is correct and equals $$x(1-x)$$ for $$0 \leq x \leq 1$$.

I assume your question is how to simplify the expression into $$x(1-x)$$?

I was able to hack a solution, and unfortunately I don't think it scales very well to other expressions. But here goes:

First, evaluate the sum:

sum = 1/6 - Sum[Cos[2 x Pi n]/(Pi n)^2, {n, 1, Infinity}];


## Non rigorous approach

If you don't care about complete rigor and abuse some mathematical rules, we can get your answer very easily:

PowerExpand[FunctionExpand[sum]]

1 - (1 - x)^2 - x


## Rigorous approach

If you want to be 100% sure things are correct, you need to give PowerExpand your assumptions:

rigor = PowerExpand[FunctionExpand[sum], Assumptions -> 0 < x < 1] Here's where Mathematica starts to have a hard time and we need to explicitly tell it what to do.

Seeing all the Floor[], maybe we should express it as a piecewise function, and simplify each part separately. This will hopefully get rid of them:

rigor = FullSimplify[PiecewiseExpand[rigor, 0 < x < 1]] Now, we see we are left with Arg. The system seems to have a hard time dealing with Arg, so I transform the relations in terms of Re and Im:

rigor = rigor /. {
Arg[expr_] <= 0 :> (ComplexExpand[Im[expr] < 0 || Im[expr] == 0 && Re[expr] >= 0])
} Finally, we want to simplify each piecewise condition with Reduce:

ReducePiecewise[expr_, x_, assum_: True] :=
FullSimplify[
expr /. HoldPattern[Piecewise][l_, r___] :>
Piecewise[Transpose[{#1, Reduce[# && assum, x]& /@ #2}& @@ Transpose[l]], r],
assum
]

ReducePiecewise[rigor, x, 0 < x < 1]

-(-1 + x) x

• Here's the whole business in one line: Assuming[0 <= x <= 1, FullSimplify[FunctionExpand[FourierSequenceTransform[If[k == 0, 1/6, -(1/(2 (π k)^2))], k, x, FourierParameters -> {1, -2 π}]] // PowerExpand]] – J. M.'s ennui Dec 19 '16 at 11:16
• What do you mean by the "non rigorous" answer? That it's just of the same form as the original function but not equal? – Leponzo Jul 18 '20 at 17:38
• No, that solution uses PowerExpand which uses generic identities like (a^b)^c == a^(b c) that are not always true. – Chip Hurst Jul 19 '20 at 1:01
• Unfortunately, PowerExpand[ FunctionExpand[-(1/\[Pi]^3) I (-\[Pi]^2 Log[1 - E^(I \[Pi] x)] + \[Pi]^2 Log[ E^(-I \[Pi] x) (-1 + E^(I \[Pi] x))] + 2 \[Pi]^2 Log[1 + E^(I \[Pi] x)] - 2 \[Pi]^2 Log[E^(-I \[Pi] x) (1 + E^(I \[Pi] x))] - 2 PolyLog[3, -E^(-I \[Pi] x)] + 2 PolyLog[3, E^(-I \[Pi] x)] + 2 PolyLog[3, -E^(I \[Pi] x)] - 2 PolyLog[3, E^(I \[Pi] x)])]] does not work (see a more complicated case in mathematica.stackexchange.com/questions/226148/…). – user64494 Jul 19 '20 at 16:15