Python Forum
Why getting ValueError : Math domain error in trig. function, math.asin() ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why getting ValueError : Math domain error in trig. function, math.asin() ?
#1
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
Reply
#2
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
jahuja73, nilamo, Gribouillis like this post
Reply
#3
(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 n
I 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.
Reply
#4
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.
nilamo likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  __dict__ in math library akbarza 6 876 Sep-28-2023, 08:23 AM
Last Post: buran
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 1,733 Jul-19-2023, 04:13 PM
Last Post: deanhystad
  math problem for experts miltmobley 5 933 Jul-09-2023, 07:14 AM
Last Post: Gribouillis
  Peaks in time domain frohr 0 451 Jul-06-2023, 02:57 AM
Last Post: frohr
  Math python question Deonvek 6 1,089 Apr-05-2023, 09:27 PM
Last Post: deanhystad
  math formula does not give the same result as bash script [SOLVED] AlphaInc 3 921 Apr-02-2023, 07:21 PM
Last Post: AlphaInc
  Convert SQLite Fetchone() Result to float for Math Extra 13 3,390 Aug-02-2022, 01:12 PM
Last Post: deanhystad
Question Parameterized math calculations? babaliaris 7 16,851 Jun-01-2022, 10:19 AM
Last Post: Gribouillis
  math.log versus math.log10 stevendaprano 10 2,314 May-23-2022, 08:59 PM
Last Post: jefsummers
  Math Package in python Uma 1 1,462 Dec-12-2021, 02:01 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020