Why getting ValueError : Math domain error in trig. function, math.asin() ? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Why getting ValueError : Math domain error in trig. function, math.asin() ? (/thread-32657.html) |
Why getting ValueError : Math domain error in trig. function, math.asin() ? - jahuja73 - Feb-24-2021 Unable to see why error in output. Tried on repl.it, as well as ideone.com; and get the same error. #your code goes here import math # number a = 2 print("asin(",a,") is = ", math.asin(a))Output: Traceback (most recent call last): File "./prog.py", line 6, in <module> ValueError: math domain error RE: Why getting ValueError : Math domain error in trig. function, math.asin() ? - Serafim - Feb-24-2021 2 is outside the interval for which asin is defined. Pythons math.asin is an implemetation of arc sine and thus it is defined for values between -1.0 and 1.0 RE: Why getting ValueError : Math domain error in trig. function, math.asin() ? - jahuja73 - Feb-24-2021 (Feb-24-2021, 12:01 PM)Serafim Wrote: 2 is outside the interval for which asin is defined. Pythons math.asin is an implemetation of arc sine and thus it is defined for values between -1.0 and 1.0 Agreed, but took it from a SO post on computing square roots using trigonometry, at : https://stackoverflow.com/a/17410692/3693431. The code is not in python, but on translation it should be: n = 5; #number to get the square root of icr = ((n+1)/2); #intersecting circle radius sqrt = Math.cos(Math.asin((icr-1)/icr))*icr; /#square root of nI hope though the code is not in python, should behave same. Even the working principle wasn't (and still is not) clear. To understand that, wanted to put prints; but it gave error straight away; leading to this question. RE: Why getting ValueError : Math domain error in trig. function, math.asin() ? - bowlofred - Feb-24-2021 That function will work because for most inputs, the argument to math.asin will be between 0 and 1. If you printed out the variables there it should work fine. |