Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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) ? –  Corey Kelly Jun 6 '13 at 14:37
    
@CoreyKelly, no, I don't need that –  wdg Jun 6 '13 at 15:17
add comment

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
1  
Since the relevant functions are Listable, I'd do (# - γ)/(1 - γ) & myself... for that matter, why not Line[(a - γ)/(1 - γ)]? –  J. M. Jun 6 '13 at 15:02
add comment

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

share|improve this answer
add comment

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"}]]
share|improve this answer
    
The primary advantage, of course, is you don't have to fiddle with the PlotRange. +1 –  rcollyer Jun 6 '13 at 14:58
    
(I know I could have done the transformation with a judicious combination of translation and scaling, but this seemed more compact.) –  J. M. Jun 6 '13 at 15:03
    
Why do you need the With in this case? It seems to work fine without it. –  Jonathan Shock Jun 6 '13 at 16:44
1  
@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. –  J. M. Jun 6 '13 at 16:47
    
Thanks @0x4A4D, very reasonable. –  Jonathan Shock Jun 6 '13 at 16:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.