1
$\begingroup$

EasyFourier by @xzczd is a nice package to obtain a Fourier series in closed form, e.g.

f = x^2
easyFourierTrigSeries[f, {x, -\[Pi], \[Pi]}, \[Infinity]]

enter image description here

However, the output cannot be manipulated symbolically, at least I don't know how to. For instance, differentiating the Fourier series is not possible like this:

D[easyFourierTrigSeries[f, {x, -\[Pi], \[Pi]}, \[Infinity]],x]

enter image description here

What I would like to do is something comparable to the following, where I have copied the summand manually into a regular Mathematica Sum:

enter image description here

BTW: How do I downscale the size of pictures in stack exchange? Is there no easier way to insert Mathematica output? How can I insert complicated Mathematica input code in 2d-mode? (Thanks for hints to these "meta" questions, too.)

$\endgroup$
3
  • 1
    $\begingroup$ Perhaps ReleaseHold? D[ReleaseHold@easyFourierTrigSeries[f, {x, -\[Pi], \[Pi]}, \[Infinity]], x] gives 2 (I Log[1 + E^(-I x)] - I Log[1 + E^(I x)]). $\endgroup$
    – Domen
    Aug 28, 2021 at 15:22
  • $\begingroup$ @Domen, that's the evaluated form. What I need is the Out[94]. $\endgroup$ Aug 28, 2021 at 16:27
  • 1
    $\begingroup$ I have provided an answer. As for the images: you can change the size of the image on StackExchange by using pure html tag as described in the Advanced Markdown help. Furthermore, SE-Tools is a really nice tool to quickly upload images from Mathematica to SE. $\endgroup$
    – Domen
    Aug 28, 2021 at 16:50

1 Answer 1

3
$\begingroup$

Inactivate has attribute HoldFirst, that is why Inactivate[ft, Sum] by itself doesn't inactivate your sum. You have to first bypass this HoldFirst with Evaluate.

ft = easyFourierTrigSeries[f, {x, -\[Pi], \[Pi]}, \[Infinity]]
D[Inactivate[Evaluate[ft], Sum] // ReleaseHold, x]

(* Inactive[Sum][-((
  4 (-1)^\[FormalK] Sin[\[FormalK] x])/\[FormalK]), {\[FormalK], 
  1, \[Infinity]}] *)

Let's take a look at some of the examples to better understand how Inactivate works:

5 + 3
(* 8 *)

Inactivate[5 + 3, Plus]
(* Inactive[Plus][5, 3] *)

Activate[Inactivate[5 + 3, Plus], Plus]
(* 8 *)

x = Hold[5 + 3]
(* Hold[5 + 3] *)

Inactivate[x, Plus]
(* Hold[5 + 3] *)

Inactivate[Hold[5 + 3], Plus] 
(* Hold[Inactive[Plus][5, 3]] *)

Inactivate[Evaluate[Hold[5 + 3]], Plus]
(* Hold[Inactive[Plus][5, 3]] *)

As you can see in the fifth example, Inactivate cannot penetrate inside x and "see" that there is a Plus (because it has attribute HoldFirst), so it doesn't inactivate it.

If you look at the documentation of Evaluate, it says: You can use Evaluate to override HoldFirst etc. attributes of built-in functions. And this is exactly what we need in this case: we use evaluate, but this doesn't mean that 5 + 3 will instantly be replaced with 8. Instead, Inactivate will be able to creep inside x and inactivate Plus.

$\endgroup$
3
  • $\begingroup$ Great, that is exactly what I was looking for! Thanks also for your hints on the meta issues. $\endgroup$ Aug 28, 2021 at 17:17
  • $\begingroup$ I'm not very familiar with Mathematica yet, and I have problems understanding why your solution works. Why does the Holdfirst attribute prevent Inactivate to work properly in this case (normally it does not)? And why do we therefore need Evaluate? This seems highly contradictory, since what we want is ft not to be evaluated, but to be inactivated. Can you possibly explain that in a few more words? $\endgroup$ Aug 28, 2021 at 21:21
  • $\begingroup$ Thank you very much, I see the point now! $\endgroup$ Aug 29, 2021 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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