This question has appeared in various forms online, but I have not yet seen a complete answer, so I am posting it here.
More specifically, suppose I have a function
F: X->Y
that is not one-to-one. Mathematica can easily plot this function as follows:
Plot[F[x], {x, 0, 30}, PlotRange -> {{0, 30}, {0, 1}}]
This produces a graph that passes the vertical line test, but does not pass the horizontal line test, because F is not one-to-one. My question is, how do I get a plot of the inverse relation (which is not a function) for all Y?
Edit: I am adding the function F for clarity. I originally omitted it because I figured a generic solution would solve it.
F[x_] := (1000 * x) / 24279 * Sqrt[-1 + x^(2/7)]
Edit 2: I am adding the graph (that I am trying to graph the inverse relation of) I produced using Plot for further clarity.
To be clear, this image is produced by the following three commands:
F[x_] := (1000 * x) / (24279 * Sqrt[-1 + x^(2/7)])
myplot = Plot[F[x], {x,0,30}, PlotRange -> {{0,30}, {0,1}}]
Export["foo.png", myplot]
Answer
Update:
Using the example function provided in op's update:
ff[x_] := (1000*x)/(24279*Sqrt[-1 + x^(2/7)]);
prmtrcplt1 = ParametricPlot[{x, ff[x]}, {x, 0, 30},
PlotRange -> {{0, 30}, {0, 1}}, ImageSize -> 300, AspectRatio -> 1];
prmtrcplt2 = ParametricPlot[{ff[x], x}, {x, 0, 30},
PlotRange -> Reverse[PlotRange[prmtrcplt1]], ImageSize -> 300, AspectRatio -> 1];
Row[{prmtrcplt1, prmtrcplt2}, Spacer[5]]
plt = Plot[ff[x], {x, 0, 30}, PlotRange -> {{0, 30}, {0, 1}},ImageSize -> 300,
AspectRatio -> 1];
ref1 = MapAt[GeometricTransformation[#, ReflectionTransform[{-1, 1}]] &, plt, {1}];
ref2 = plt /. line_Line :> GeometricTransformation[line, ReflectionTransform[{-1, 1}]];
Row[{plt, Graphics[ref1[[1]], PlotRange -> Reverse@PlotRange[ref1], ref1[[2]]],
Graphics[ref2[[1]], PlotRange -> Reverse@PlotRange[ref2], ref2[[2]]]}, Spacer[5]]
original post
ParametricPlot (as suggested by whuber)
prmtrcplt1 = ParametricPlot[{x, x Sin[2 x]}, {x, -Pi, Pi},
PlotRange -> {{-Pi, Pi}, {-3, 3}}, ImageSize -> 300];
prmtrcplt2 = ParametricPlot[{x Sin[2 x], x}, {x, -Pi, Pi},
PlotRange -> {{-Pi, Pi}, {-3, 3}}, ImageSize -> 300];
Row[{prmtrcplt1, prmtrcplt2}, Spacer[5]]
Post-process using ReflectionTransform
reflected = plt /. line_Line :> {Red,
GeometricTransformation[line, ReflectionTransform[{-1, 1}]]};
Row[{plt, reflected,
Show[plt, Plot[x, {x, -Pi, Pi}, PlotStyle -> Black], reflected,
PlotRange -> All, ImageSize -> 300]}, Spacer[5]]
Variations:
reflected2 = MapAt[GeometricTransformation[#, ReflectionMatrix[{-1, 1}]] &, plt, {1}];
reflected3 = MapAt[GeometricTransformation[#, ReflectionTransform[{-1, 1}]] &,plt, {1}]
Comments
Post a Comment