4

I want an operator that takes as input a function of a real variable e.g. f(x) and returns as output the answer f(-x). How does one define such an operator in Mathematica?

kglr
  • 394,356
  • 18
  • 477
  • 896
Quasar Supernova
  • 1,678
  • 8
  • 13

3 Answers3

6

You can define such a operator like so.

yAxisReflect[f_] := (f[-#] &)

where f is a symbol naming a function or a pure function.

With this definition, you can do things like

Plot[{Sin[x], yAxisReflect[Sin][x]}, {x, -π, π}]

sine

Plot[{(1 + x)^2, yAxisReflect[(1 + #)^2 &][x]}, {x, -2, 2}]

square

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
4

One approach is to define a "negative" function directly:

g[x_] := f[-x]

So however f[x] is defined, g[x] gives f[-x]. But really, why do this? Wouldn't it be simpler and clearer just to use f[-x] directly whenever needed?

bill s
  • 68,936
  • 4
  • 101
  • 191
1
ClearAll[reflectionF1, reflectionF2]
reflectionF1[f_] := Compose[f, Minus, #] &;
reflectionF2[f_] := Composition[f, Minus] (* f @* Minus  in V 10.0+ as suggested by JM *)

Using m_goldberg's example setup:

Row[{Plot[{Sin[x], reflectionF1[Sin][x]}, {x, -\[Pi], \[Pi]}, 
   PlotLabel -> Style["reflectionF1", 16, "Panel"], ImageSize -> 400, PlotStyle -> Thick], 
  Plot[{Sin[x], reflectionF2[Sin][x]}, {x, -\[Pi], \[Pi]},
   PlotLabel -> Style["reflectionF2", 16, "Panel"], ImageSize -> 400, PlotStyle -> Thick]}]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896