Posts: 13
Threads: 2
Joined: Jan 2024
I am trying to calculate minute angles, and would like precision of at least 15 digits:
But I fail to understand how Python is rounding.
As I vary the value of asin by factors of 10 (from .001 to .00001), the output adds these zeros between the leading numeral 1 and the next numeral 1 (and some sixes after). See the image below.
And this is happening whether I use the gimpy2 or math modules:
Does the Sin -1 actually do this on radians?
Degrees acts similarly: When the input is very small and changes by a factor of ten (eg., .001 - .00001), the output of asin only changes by a factor of ten — the decimal point just moves one place while leaving the significant figures virtually unchanged.
Thank you!!
A version of the test code being used is shown below:
import gmpy2
import math
from gmpy2 import *
from gmpy2 import get_context as ctx
ctx().precision = 100
# L = mpfr('1000.0')
F = 0.00001
N = 10.0
B = 0.5
C = gmpy2.div(F, N)
c = F / N
D = 2 * C
d = 2 * c
E = B * gmpy2.asin(D)
e = B * math.asin(d)
g = .000002
e2 = B * math.asin(g)
# F = gmpy2.mul(B, E)
# sin(2 * theta) = 2 * sin(theta)cos(theta)
# print("L: ", L, type(L))
print("F: ", F, type(F))
print("N: ", N, type(N))
print("B: ", B, type(B))
print("C: ", C, type(C))
print("c: ", c, type(c))
print("D: ", D, type(D))
print("d: ", d, type(d))
print("E: ", E, type(E))
print("e: ", e, type(e))
print("e2: ", e2, type(e2))
print(ctx())
Posts: 13
Threads: 2
Joined: Jan 2024
Maybe this is a clue. I get this error:
get_context.round = RoundUp
AttributeError: 'builtin_function_or_method' object has no attribute 'round'
Posts: 13
Threads: 2
Joined: Jan 2024
I went to a random calculator website: https://math.tools/calculator/trignometry/asin
From there I found similar results and created a table of the values (see image below):
I know the circle looks pretty flat (linear), when the angle is very small, but the radian numbers are just spooking me (the zeros and sixes).
On the other hand, the values in the "Degrees" column in the table do not look so bad — they change in a way that does not appear as weird. Maybe degrees are a more comforting unit to work with in this case (and they are about 60 times smaller than radians).
Posts: 13
Threads: 2
Joined: Jan 2024
get_context ().round works, sorry.
Posts: 54
Threads: 0
Joined: Oct 2016
(Jan-22-2024, 03:44 AM)charlesrkiss Wrote: I went to a random calculator website: https://math.tools/calculator/trignometry/asin
From there I found similar results and created a table of the values (see image below):
I know the circle looks pretty flat (linear), when the angle is very small, but the radian numbers are just spooking me (the zeros and sixes).
On the other hand, the values in the "Degrees" column in the table do not look so bad — they change in a way that does not appear as weird. Maybe degrees are a more comforting unit to work with in this case (and they are about 60 times smaller than radians). 
The values look fine to me. Some
Assuming is in radian, x is between -1 and 1, then asin(x) can be approximated by x + (x**3 / 6) + (3 * x**5 / 40) + ....
Let's try it with x =0.01.
asin(0.01) = 0.01 + (0.000001/6) + (3 *0.0000000001/40)
which becomes
asin(0.01) = 0.01 + 0.000000166666666... + 0.0000000000075
or
0.010000166674166668
Sorry about the lack of formatting and terseness.
Posts: 13
Threads: 2
Joined: Jan 2024
Thank you Case.
JTLYK, I spent hours carefully looking into the significands (see video), first and second 'derivatives,' and stretching limits (see image), including working with the different rounding types. And yes, it is ALL PERFECT and SO impressive.
Some plots using RoundToNearest, when I was at the limit:
I'm so grateful for your help, and putting me on the right track. Gmpy2 works exactly as expected, once I started moving up the learning curve a bit. Now I can get back to the actual math (that I virtually forgot over these last few days).
I would like to add that I use the GNU graphics software GIMP a lot, and it's really funny that I keep adding a letter "I" and must backspace to delete it.
If you need any images and I could save you some time, please let me know.
Thank you so much !!!
forum.mp4 (Size: 1,020.1 KB / Downloads: 64)
Posts: 1
Threads: 0
Joined: Jun 2024
Jun-14-2024, 09:53 AM
(This post was last modified: Aug-06-2024, 09:58 AM by Larz60+.)
The asin function's output for small values approximates the input itself due to its Taylor series expansion around zero. Floating-point precision causes minor discrepancies. Use gmpy2 with higher precision to minimize rounding errors and achieve greater accuracy.
Larz60+ write Aug-06-2024, 09:58 AM:clickbait link removed
Posts: 2
Threads: 0
Joined: Aug 2024
Aug-06-2024, 09:56 AM
(This post was last modified: Aug-06-2024, 10:16 AM by Gribouillis.)
(Jan-21-2024, 11:54 PM)charlesrkiss Wrote: I am trying to calculate minute angles, and would like precision of at least 15 digits:
But I fail to understand how Python is rounding.
As I vary the value of asin by factors of 10 (from .001 to .00001), the output adds these zeros between the leading numeral 1 and the next numeral 1 (and some sixes after). See the image below.
And this is happening whether I use the gimpy2 or math modules:
Does the Sin-1 actually do this on radians?
Degrees acts similarly: When the input is very small and changes by a factor of ten (eg., .001 - .00001), the output of asin only changes by a factor of ten — the decimal point just moves one place while leaving the significant figures virtually unchanged.
Thank you!!
A version of the test code being used is shown below:
import gmpy2
import math
from gmpy2 import *
from gmpy2 import get_context as ctx
ctx().precision = 100
# L = mpfr('1000.0')
F = 0.00001
N = 10.0
B = 0.5
C = gmpy2.div(F, N)
c = F / N
D = 2 * C
d = 2 * c
E = B * gmpy2.asin(D)
e = B * math.asin(d)
g = .000002
e2 = B * math.asin(g)
# F = gmpy2.mul(B, E)
# sin(2 * theta) = 2 * sin(theta)cos(theta)
# print("L: ", L, type(L))
print("F: ", F, type(F))
print("N: ", N, type(N))
print("B: ", B, type(B))
print("C: ", C, type(C))
print("c: ", c, type(c))
print("D: ", D, type(D))
print("d: ", d, type(d))
print("E: ", E, type(E))
print("e: ", e, type(e))
print("e2: ", e2, type(e2))
print(ctx())
For precise minute angle calculations, try using Link Removed Calculadora Alicia de! It offers high accuracy and can help ensure your results are spot-on, especially when dealing with floating-point limitations in Python.
|