For example square root of 25 is +5 and -5. But in python we get only the positive values.
import math
x=math.sqrt(25)
y=16**0.25
print(x,y)
We get output as 5,2 not -5,-2. How to get both the values?
For example square root of 25 is +5 and -5. But in python we get only the positive values.
import math
x=math.sqrt(25)
y=16**0.25
print(x,y)
We get output as 5,2 not -5,-2. How to get both the values?
Unfortunately!, python still has no direct operation to get both plus/minus
If you really need to get both values then you can use uncertainties. The uncertainties package is a free, cross-platform program that transparently handles calculations with numbers with uncertainties (like 3.14±0.01). It can also yield the derivatives of any expression.
First, you need to install uncertainties
. If you use pip
, then
pip install --upgrade uncertainties
After that import modules in your file and do your operation.
import math
from uncertainties import ufloat
from uncertainties.umath import *
y=16**.25
print(x*math.sqrt(25), x*y)
# Output
# 5+/-5 2.0+/-2.0
Also, You have more quest then go through this answer.