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?
Asked
Active
Viewed 156 times
4
kglr
- 394,356
- 18
- 477
- 896
Quasar Supernova
- 1,678
- 8
- 13
3 Answers
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, -π, π}]
Plot[{(1 + x)^2, yAxisReflect[(1 + #)^2 &][x]}, {x, -2, 2}]
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]}]
kglr
- 394,356
- 18
- 477
- 896



f[x] /. h_[a_]:>h[-a]but I guess the best solution may be background dependent. So what it the big picture here? What have you tried? – Kuba Sep 12 '17 at 10:08f @* Minus. – J. M.'s missing motivation Sep 12 '17 at 16:23