0

This question is a continuation of this one.

I used the answer provided in the previous question to write this code

g[f_][x_?NumericQ] := If[EvenQ@Floor[x], f@FractionalPart[x], 1/f@FractionalPart[x]]

for an arbitrary pure function $f$. It works for many things but it cannot be integrated or differentiated properly. One example: this code

Integrate[g[1 + Sin[Pi #] &][x], {x, 0, 2}]

stay unevaluated. If I use instead NIntegrate I can get a numerical result. But Im interested in the symbolic result. In the same way this code

g[1 + Sin[Pi #] &]'[3]

stay unevaluated. Of course this code doesnt work also

Plot[D[g[1 + Sin[Pi #] &][x], x], {x, 0, 2}, Exclusions -> {Sin[2 Pi x] == 0}]

In short: I dont know how to differentiate or integrate these operated functions. Some help will be appreciated.

Masacroso
  • 1,107
  • 5
  • 13
  • 1
    For one sub-issue with plotting derivatives, start here: https://mathematica.stackexchange.com/questions/35355/plot-dsinx-and-evaluate – Michael E2 May 11 '17 at 16:05

1 Answers1

3

Rather than using EvenQ, which always evaluates to a boolean, I would use something like Mod, which remains unevaluated for non-numeric arguments:

g[f_][x_] := If[Mod[Floor[x], 2] == 0,
    f@FractionalPart[x],
    1/f@FractionalPart[x]
]

Then:

expr = g[1 + Sin[π #] &][x]
Integrate[expr, {x, 0, 2}]

If[Mod[Floor[x], 2] == 0, (1 + Sin[π #1] &)[ FractionalPart[x]], 1/(1 + Sin[π #1] &)[FractionalPart[x]]]

(4 + π)/π

Carl Woll
  • 130,679
  • 6
  • 243
  • 355