Pardon if I didn't ask the question correctly. Still trying to figure out the language. I have the following expression: $$energy=\frac{1}{2}R_s^{'}[t]^2==\frac{4}{3}G\pi\rho R_s[t]^2$$

energy = (1/2)*Derivative[1][Subscript[R, s]][t]^2 == (4/3)*G*
   Pi*\[Rho]*Subscript[R, s][t]^2

I have the following identity: $$R_s[t]==a[t]r_s$$ When I make this substitution: $$energy/.R_s[t]\rightarrow a[t]r_s$$

energy /. Subscript[R, s][t] -> a[t]*Subscript[r, s]

I get this result:

$$\frac{1}{2}R_s^{'}[t]^2 == \frac{4}{3}G\pi\rho R_s[t]^2$$

(1/2)Derivative[1][Subscript[R, s]][t]^2 == (4/3)GPi[Rho]a[t]^2 Subscript[r, s]^2

What do I need to do for the derivative $R_s^{'}[t]^2$ to understand the substitution. I was expecting the result to be:

$$\frac{1}{2}r_s a'[t]^2 == \frac{4}{3}G\pi\rho (r_s a[t])^2$$

EDIT: Accessing external code is a bad idea and should be avoided at all costs. It's just one more thing that can go wrong when sharing code. I'm looking for a solution that solves this problem with the native Mathematica instructions.

  • $\begingroup$ Why isn't R_s in the right hand side of the final result substituted? $\endgroup$
    – Kuba
    Jul 9, 2020 at 5:19
  • $\begingroup$ Please see the duplicate thread and topics linked there. $\endgroup$
    – Kuba
    Jul 9, 2020 at 5:23
  • 1
    $\begingroup$ energy /. {Subscript[R, s] -> (Subscript[r, s] a[#] &)} $\endgroup$
    – Bill Watts
    Jul 9, 2020 at 5:56

1 Answer 1


Quick solution:

energy /. Subscript[R, s] -> Function[t, a[t]*Subscript[r, s]]

enter image description here

Or using linked answer:

DChange[energy, Subscript[R, s][t] == a[t]*Subscript[r, s]]
  • $\begingroup$ I can't speak for everyone with the same problem, but your first solution seems to be the simplest one as it's a single line and uses just Mathematica. I'm not a big fan of external code in my solutions. One more thing to go wrong. $\endgroup$
    – Quark Soup
    Jul 9, 2020 at 10:22
  • $\begingroup$ @Quarkly sure, fair enough. Linked topic links to old solutions that are basically the same as the first line here so the duplicate works like a central hub rather than the only way to go. DChange uses the same method btw. $\endgroup$
    – Kuba
    Jul 10, 2020 at 7:33

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