1
$\begingroup$

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, π}}]

Plot of the transformation... works as expected

So how do I make plots of things like:

Plot[Cos[XPrimed[x]], {x,-π, π},
    AxesLabel -> {"original variable, x", "Cos(x')"}]

Plot of the transformed variable

..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.

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

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"]}]

enter image description here

$\endgroup$
1
$\begingroup$
ParametricPlot[{XPrimed[x], Cos[XPrimed[x]]}, {x, -\[Pi], \[Pi]}, 
  PlotStyle -> Thick, 
  AxesLabel -> (Style[#, 16] & /@ {"transformed variable, x'",  "Cos(x')"})]

enter image description here

$\endgroup$
  • $\begingroup$ That's really useful. Thanks! $\endgroup$ – samcunliffe Jun 22 '14 at 16:27

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.