TransWikia.com

Can I use Solve to solve for an expression (instead of a variable)?

Mathematica Asked on May 22, 2021

I have an equation:$$ds^2=-(C_1+Aspace t)^2 dt^2+C_2^2 dr^2$$How would I re-arrange this formula to get an expression of $frac{dr}{dt}$? $C_1$, $C_2$ and $A$ are constants. I know the answer is:$$frac{dr}{dt}=frac{ds+(C_1+Aspace t)dt}{C_2 dt}$$This would allow me to make a substitution of $D[r,t]=frac{dr}{dt}$ and solve the problem as an ODE, but I’m stuck trying to get the LHS of the equation in this form. Ideally, I’d like to do this:

Solve[ds^2=-(C_1+A*t)^2 dt^2+C_2^2 dr^2,dr/dt]

Are there any tricks?

One Answer

First of all, let us mention two syntax errors in your code.

First, the underscore has a special meaning in Mma. Therefore, notations like C_1 are illegal. Use C1 instead.

Second, the use of Solve requires that the Equal, rather than Set stays in the expression you want to be interpreted as an equation. Therefore, use == instead of =.

After fixing this, the answer to your question is not very difficult. I will do it starting with your original idea.

Here is your equation and its solution:

sol = Solve[ds^2 == -(C1 + A*t)^2 dt^2 + C2^2 dr^2, dr][[2, 1]]


(*  dr -> Sqrt[ds^2 + C1^2 dt^2 + 2 A C1 dt^2 t + A^2 dt^2 t^2]/C2 *)

By default, Mma returns the solution in the form of a rule. Let us transform it into an equation:

eq1 = Equal @@ sol

(*  dr == Sqrt[ds^2 + C1^2 dt^2 + 2 A C1 dt^2 t + A^2 dt^2 t^2]/C2  *)

Let us now divide the both parts of this equation by dt:

eq2 = Assuming[{dt != 0}, DivideSides[eq1, dt]]

(*  dr/dt == Sqrt[ds^2 + C1^2 dt^2 + 2 A C1 dt^2 t + A^2 dt^2 t^2]/(C2 dt)  *)

Now, let us bring dt under the square root:

eq3 = expr1 /. Sqrt[a_]/dt :> Sqrt[a/dt^2]

(*  dr/dt == Sqrt[(
 ds^2 + C1^2 dt^2 + 2 A C1 dt^2 t + A^2 dt^2 t^2)/dt^2]/C2  *)

and let us, further, expand the expression under the radical:

MapAt[Expand, expr2, {2, 2, 1}]

(*  dr/dt == Sqrt[C1^2 + ds^2/dt^2 + 2 A C1 t + A^2 t^2]/C2   *)

Done. Have fun!

Correct answer by Alexei Boulbitch on May 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP