Python Forum
Get the value of arcsine(x) in a manner that I can understand.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the value of arcsine(x) in a manner that I can understand.
#1
I was never good at maths!

Now, I want to get the value of arcsine(y), given any particular sine(x) = y

I can plot sine(x), and, as I understand it, maybe I'm wrong, from my plot, given a particular value of sine(x), I should be able to draw a horizontal line through y, where that line meets my graph, go down to the x axis and I should have the value of the angle corresponding to x in radians. If I multiply that value by π/180 I hope I will get the value in degrees, and so I hope to have reversed the function y = sine(x) and got the value of the angle from the value of sine((x)

Trouble is, I don't really understand what I am doing, it's maths!

This plots sine(x) with -π/2 ≤ x ≤ π/2

How can I get the value of the x axis for any value of y = sine(x)

def myApp():
    import matplotlib.pyplot as plt
    import numpy as np

    # 100 linearly spaced numbers
    x = np.linspace(-np.pi/2,np.pi/2,200)

    # the function, which is y = sin(x) here
    y = np.sin(x)

    # setting the axes at the centre
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.spines['left'].set_position('center')
    ax.spines['bottom'].set_position('center')
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')

    # plot the function
    plt.plot(x,y, 'b-')

    # show the plot
    plt.show()
Reply
#2
Why not use the math module?
>>> import math
>>> y = 0.7
>>> x = math.asin(y)
>>> x
0.775397496610753
>>> math.degrees(x)
44.4270040008057
Also the important thing to know about arcsine is that for a value -1 <= y <= 1 it gives the unique angle -pi/2 <= x <= pi/2 such that sin(x) == y, but there are other angles t outside this interval such that sin(t) == y, namely t = x + 2 * k * pi or t = pi - x + 2 * k * pi where k is any integer.
Pedroski55 likes this post
Reply
#3
Thanks! That makes life easy!

What I would like to know is, how do they achieve that result, practically and internally? Solve an integral?

The numpy module has an arcsin function too I see.

I tried this to help me understand arcsin(x)

x = np.linspace(-np.pi/2,np.pi/2,2000)
y = np.sin(x)
sine_angle_dict = {y[a]:(x[a], math.degrees(x[a])) for a in range(len(x))}
For any given sine(x) I could look in my dictionary to find the closest value to my sine(x) and print the angle. Not perfect, but an approximation I can understand!
Reply
#4
I was searching wrong!

I should have searched for "Algorithm for calculating arctan (x)"

Basically, you use arctan to get arcsin. Here is a link if you are interested.
Reply
#5
(May-21-2023, 10:57 PM)Pedroski55 Wrote: Basically, you use arctan to get arcsin.
Several mathematical algorithms can be used to compute arcsin. Here is an implementation in openlibm for example, using rational functions. Here is the glibc implementation for ieee754.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I rearrange df as the nodes index in pytorch geometric manner? uqlsmey 0 513 Jul-31-2023, 11:28 AM
Last Post: uqlsmey

Forum Jump:

User Panel Messages

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