# What is the 'Mathematica-way' to test a variable transform?

Hello Mathematica experts.

I would like to play around with a simple variable transformation, to test some claims about it. I wonder if there is a Mathematica-like way to do this.

The specific case I have is a transformation: $$x\mapsto x' \equiv \begin{cases}x; \qquad x\ge 0\\x+\pi;\, x<0\end{cases}$$ where $x\in[-\pi,\pi]$ gets moved over to $x'\in[0,\pi]$.

So far I have found two equivalent ways of representing this:

XPrimed[x_] := If[x < 0, x + π, x]
AnotherXPrimed[x_] := x*HeavisideTheta[x]  + (HeavisideTheta[-x]*(x + π))


Which both seem reasonable.

Plot[XPrimed[phi], {phi, -π, π},
AxesLabel -> {"original variable, x", "transformed variable, x'"},
PlotRange -> {{-π, π}, {0, π}}] So how do I make plots of things like:

Plot[Cos[XPrimed[x]], {x,-π, π},
AxesLabel -> {"original variable, x", "Cos(x')"}] ..but over the transformed domain, i.e. $\cos(x')$ with $x'$ on the x-axis? I suspect there is a smart way to do this in Mathematica specifying domains or variable maps or a coordinate transformation or the like, I can't seem to find anything.

• Take a minute to think what you are asking - does it make any difference whether the variable is primed or not in your question? – gpap Jun 22 '14 at 11:32
• Here is another valid way to define XPrimed: XPrimed[x_] := Piecewise[{{x, x >= 0}, {x + π, x < 0}}] – m_goldberg Jun 22 '14 at 12:23

## 2 Answers

As per m_goldberg, you can define transform as function and compose e.g.

g[x_] := Piecewise[{{x, x >= 0}, {x + Pi, True}}]
Plot[g[x], {x, -3, 3}, PlotLegends -> "Expressions"],
Plot[Cos[g[x]], {x, -3, 3}, PlotLegends -> "Expressions"]}] ParametricPlot[{XPrimed[x], Cos[XPrimed[x]]}, {x, -\[Pi], \[Pi]},
PlotStyle -> Thick,
AxesLabel -> (Style[#, 16] & /@ {"transformed variable, x'",  "Cos(x')"})] • That's really useful. Thanks! – samcunliffe Jun 22 '14 at 16:27