What's wrong with naming a rule?
This version works:
rl = {ρ[z_, ϕ_] :> 1/5 Sqrt[25 - 25 z^2 + 10 Sin[5 ϕ] + Sin[5 ϕ]^2]};
Manipulate[PolarPlot[Evaluate[ReplaceAll[ρ[z, ϕ], %]], {ϕ,0, 2 Pi}], {z, -1, 1}]
Manipulate[PolarPlot[Evaluate[ReplaceAll[ρ[z, ϕ], rl]], {ϕ,0, 2 Pi}], {z, -1, 1}]
The main change is in the way the rule is defined as a $RuleDelayed$ instead of $Rule$.
Thanks to ciao's and Kuba's explanation, I have thought of some little code to exemplify the scoping behaviour of Manipulate
; I hope it will be helpful to people who are still not very familiar with the concept:
a),
Manipulate[Hold@x, {x,0,1}]
b),
p=x;
Manipulate[2 p-x,{x,0,1}]
c),
rpl=q->x;
Manipulate[(2 q/.rpl)-x,{x,0,1}]
Others have explained why the version with rl
does not work. But this does not explain the very weird phenomenon that the version with %
does work. Why is %
(which is just a notation for Out
) special?
It seems that Manipulate
singles out Out
(i.e. %
) for special treatment. Observe:
In[1]:= x
Out[1]= x
In[2]:= Manipulate[Hold[%1], {x, 0, 1}]
Out[2]= Manipulate[Hold[x], {x, 0, 1}]
Manipulate
has taken the Out[1]
(same as %1
), and evaluated it, even though it was inside of Hold
. This is not normal evaluation. It is Manipulate
looking specifically for %
and replacing it with its value.
This is no doubt done to make Mathematica less confusing and more accessible to beginners. But personally I don't like this special behaviour at all. For people who already understand how Mathematica works this (undocumented!) behaviour is very surprising and completely unexpected.