0

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.

Quark Soup
  • 1,610
  • 9
  • 14

1 Answers1

3

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]]
Kuba
  • 136,707
  • 13
  • 279
  • 740
  • 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. – Quark Soup Jul 09 '20 at 10:22
  • @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. – Kuba Jul 10 '20 at 07:33