+ 5
Why Print (math.sqrt (16)) gives only +4 and not -4?
5 ответов
+ 7
As you already know x^2 = 16 have 2 solutions. (i.e. -4 and 4) and we can solve it by using the quadratic formula.
Take note the plus-minus sign ± in the formula as it consists of two operations. Therefore by applying the formula and we will get:-
sqrt(64) ÷ 2 = 4
-sqrt(64) ÷ 2 = -4
It's a common misconception to treat the square root as a *function* that return 2 possible values but in fact it only return ONE.
Conclusion:
✅ x squared have 2 possible solutions.
✅ square root of x is one of the possible solution of the problem above.
+ 4
Because functions can return only one value, and the positive one is more useful. If your program expects to use the negative value as well, you are expected to negate the value you get from Math.sqrt().
(They *could* define sqrt() to return an array with 2 members, one the positive result and the other one with the negative result, but it is easier to negate the single result than to mess with this solution.
It's also the standard way to handle this in every other programming language I know)
+ 2
- convention is itself an imaginary concept...
it invented only to undetstand or manupulate mathematics...
u dont need' - ' in counting...
if u need -4 for sqrt(16) just do -sqrt(16)
+ 1
even this print (math.sqrt((-4)**2)) gives 4...if i get x^2 =16 then x could be +-4.
0
built in functions always return one value.