1
$\begingroup$

Suppose I have the following plot:

Plot[(1 - p2)^2/(p2^2 + (1 - p2)^2), {p2, 0, 1}, AxesLabel -> {"p2", "p1"}]

enter image description here

Now I want to do a point-wise transform to every point $(p2,p1)$ on the line (making a new plot) using:

$ p1 \rightarrow \dfrac{p1-\gamma}{1-\gamma}\quad p2\rightarrow\dfrac{p2-\gamma}{1-\gamma} $

In other words, I want to move every point on the line $(p2,p1)$ to a new location $\left(\dfrac{p2-\gamma}{1-\gamma},\dfrac{p1-\gamma}{1-\gamma}\right)$.

How should I achieve that?

$\endgroup$
  • $\begingroup$ I suppose it is unclear here whether you want to maintain the relationship p2[p1] as defined in your original plot. Should p2 become (p2[p1] - gamma)/(1- gamma) -or- (p2[(p1-gamma)/(1-gamma)] - gamma)/(1- gamma) ? $\endgroup$ – Corey Kelly Jun 6 '13 at 14:37
  • $\begingroup$ @CoreyKelly, no, I don't need that $\endgroup$ – wdg Jun 6 '13 at 15:17
5
$\begingroup$

If you did want to transform the plot, you can use something like:

Manipulate[
    Plot[(1 - p2)^2/(p2^2 + (1 - p2)^2), {p2, 0, 1},
         AxesLabel -> {"p2", "p1"}, PlotRange -> {-1, 1}] /.
    Line[a__] :> Line @ Map[{(#[[1]] - γ)/(1 - γ), (#[[2]] - γ)/(1 - γ)} &, a],
   {γ, -1, 0.5}]

which transforms the points that define the Line.

$\endgroup$
  • 1
    $\begingroup$ Since the relevant functions are Listable, I'd do (# - γ)/(1 - γ) & myself... for that matter, why not Line[(a - γ)/(1 - γ)]? $\endgroup$ – J. M. is away Jun 6 '13 at 15:02
5
$\begingroup$

You probably want to transform the function, not the plot:

f[p2_] := (1 - p2)^2/(p2^2 + (1 - p2)^2)
Plot[f[p2], {p2, 0, 1}, AxesLabel -> {"p2", "p1"}]
t[p2_, g_] := (f[(p2 - g)/(1 - g)] - g)/(1 - g)
Manipulate[Plot[t[p2, g], {p2, 0, 1}, AxesLabel -> {"p2", "p1"}], {g, 0, 0.999}]

Manipulating gamma

$\endgroup$
3
$\begingroup$

I'd say this is the sort of thing LinearFractionalTransform[] was designed for:

With[{γ = 2/3}, 
     MapAt[GeometricTransformation[#,
           LinearFractionalTransform[{IdentityMatrix[2], {-γ, -γ}, {0, 0}, 1 - γ}]] &, 
           Plot[(1 - p2)^2/(p2^2 + (1 - p2)^2), {p2, 0, 1}, AxesLabel -> {"p2", "p1"},
                PlotRange -> All], 1]]

curve after a linear fractional transformation

Of course, you can use ParametricPlot[] instead of Plot[]:

With[{γ = 2/3}, 
 ParametricPlot[LinearFractionalTransform[{IdentityMatrix[2], {-γ, -γ}, {0, 0}, 1 - γ}] @ 
                {p2, (1 - p2)^2/(p2^2 + (1 - p2)^2)}, {p2, 0, 1},
                AspectRatio -> 1/GoldenRatio, AxesLabel -> {"p2", "p1"}]]
$\endgroup$
  • $\begingroup$ The primary advantage, of course, is you don't have to fiddle with the PlotRange. +1 $\endgroup$ – rcollyer Jun 6 '13 at 14:58
  • $\begingroup$ (I know I could have done the transformation with a judicious combination of translation and scaling, but this seemed more compact.) $\endgroup$ – J. M. is away Jun 6 '13 at 15:03
  • $\begingroup$ Why do you need the With in this case? It seems to work fine without it. $\endgroup$ – Jonathan Shock Jun 6 '13 at 16:44
  • 1
    $\begingroup$ @Jonathan, I certainly could have made the global assignment γ = 2/3 in before executing the plots, but I prefer not to litter the Global` context if I can help it. Besides, this is the sort of thing With[] is intended for: parameter setting. $\endgroup$ – J. M. is away Jun 6 '13 at 16:47
  • $\begingroup$ Thanks @J. M., very reasonable. $\endgroup$ – Jonathan Shock Jun 6 '13 at 16:49

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.