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_0=\frac{1}{6}$$ or


I tried:

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

enter image description here

Plot[%, {x, -3, 3},PlotRange -> 1]

enter image description here

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} $$


1 Answer 1


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:

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]

enter image description here

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]]

enter image description here

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])

enter image description here

Finally, we want to simplify each piecewise condition with Reduce:

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

ReducePiecewise[rigor, x, 0 < x < 1]
-(-1 + x) x
  • 2
    $\begingroup$ 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]] $\endgroup$ Commented Dec 19, 2016 at 11:16
  • $\begingroup$ What do you mean by the "non rigorous" answer? That it's just of the same form as the original function but not equal? $\endgroup$
    – Leponzo
    Commented Jul 18, 2020 at 17:38
  • 2
    $\begingroup$ No, that solution uses PowerExpand which uses generic identities like (a^b)^c == a^(b c) that are not always true. $\endgroup$
    – Greg Hurst
    Commented Jul 19, 2020 at 1:01
  • 1
    $\begingroup$ 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/…). $\endgroup$
    – user64494
    Commented Jul 19, 2020 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.