I have a function depending r, for example f[r_]:=2*(1/a)Exp[-r/a] I want to plot a r^2 f[r]^2 vs r/a, How to do this? I tried this Plot[a *r^2 *f[r]^2, {r/a, 0, 8}, PlotRange -> All] but it returns $Failed


1 Answer 1


Plot isn't designed to handle arbitrary expressions as a domain. Replace r with a rdividedbya where rdividedbya is a symbol name that the language can use.

Plot[a*r^2*f[r]^2/.r->a rdividedbya,{rdividedbya,0,8},PlotRange->All]

This replacement happens before the expression a*r^2*f[r] is evaluated and is effectively the same as

Plot[a*(a rdividedbya)^2*f[a rdividedbya]^2,{rdividedbya,0,8},PlotRange->All]

Replacement saved us the work of typing a rdividedbya twice. We could even be so lazy as to solve the equation $\text{rdividedbya}=\frac ra$ for $r$ with Mathematica, but that's overkill in this situation.


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.