How to use functional units in Mathematica

I would like to transfer the parameter values ​​in meters or kilometers (both possible) and get the result in meters / second.

I tried to do this in the following example:

u = 3.986*10^14 Meter^3/Second^2;
v[r_, a_] := Sqrt[u (2/r - 1/a)];

Convert[r, Meter];

Convert[a, Meter];

If I try to use a specific function and conversion:

a = 24503 Kilo Meter;
s = 10198.5 Meter/Second;
r = 6620 Kilo  Meter;
Solve[v[r, x] == s, x]

The function returns the following:

{x -> (3310. Kilo Meter^3)/(Meter^2 - 0.000863701 Kilo Meter^2)}

which is not user friendly.

In any case, I would like to determine a and r in meters or kilometers and get the result s in meters / second (meter / second).

I would be very grateful if any of you could correct this definition of a function and other instructions to get the desired result.

+3
source share
2

, , Solve , x v[r, x], Convert, :

With[{rule = First@Solve[v[r,x]==s,x] 
      (* Solve always returns a list of rules, because algebraic 
         equations may have multiple solutions. *)},
  Convert[v[r,x] /. rule, Meter/Second]]

(10198.5 Meter)/Second .

+2

Mathematica, , , "", , . , -

SimplifyWithUnits[blabla_, unit_List]:= Simplify[blalba, (#>0)&/@unit];

, , % ~ SimplifyWithUnits ~ {Meter} - .

+1

Source: https://habr.com/ru/post/1717584/


All Articles