I cannot take sqrt of units
I'm trying to use sagemath to evaluate equations that involve units. And when I hit a sqrt
of a unit it won't evaluate it.
For example:
sage: sqrt(4*units.length.meter^2)
2*sqrt(meter^2)
The result should be 2*meter
but I can't figure out how to force it to evaluate the sqrt of m^2. Even if I try to convert it like:
(sqrt(4*units.length.meter^2)).convert(units.length.meter)
I get:
ValueError: Incompatible units
Like this
Thanks. That does actually get me 1 step further. But this was a stripped down version of my overall equation. I now have another pesky part of the equation to deal with:
In some simpler equations
polynomial(RR)
helps. Is there something I'm doing wrong here constructing and evaluating these equations?I can do a similar thing in Mathematica and it allows me to call
N[]
and it reliably gives me back 1 number and a unit.Another alternative (after canonicalizing the radical) is to use an ExpressionTreeWalker to substitute numerical approximations (that should probably be built-in functionality, hidden inside a new method).