Algorithm behind Sin Function The relationship between the hypothenuse and the opposite cathetus of an angle can be described by  $$\sin\theta=\frac{a}{h}$$ , where  $a$ is the opposite cathetus, and $h$ is the hypothenuse.
But I am curious about the sine  function, it is not a variable and my math teacher defines it as a function. So if it is a function, could anyone kindly tell me how this function was found and what variable terms it is composed as?
Thanks
 A: Your teachers are correct when they say $\sin$ is a function. It's best to think of it as a function that assigns a number to each angle.
When you put that angle into a right triangle you can calculate the $\sin$ as a ratio of sides. For example, the $45^\circ$ angle is the angle in an isosceles right triangle with side length $1$, so   $\sin 45^\circ = 1/\sqrt{2}$, the ratio of the opposite side to the hypotenuse. You would get the same answer from a larger triangle, since the ratio of the sides would be the same.
You can figure out that $\sin 60^\circ$ is $\sqrt{3}/2$ by looking at an equilateral triangle and one of its altitudes.
There is no algorithm for finding the exact numerical value for  the sine of an arbitrary angle.
There are formulas with which to find the sines of sums and halves of angles. You can use those to get the sines of angles that are multiples of $3^\circ$. One of the challenges for mathematicians in ancient times was to find good approximations for $\sin 1^\circ$. They needed sines for astronomical calculations.
Nowadays there are  tools for finding as close an approximation as you need. You will learn them when you study calculus.
A: Since the sin function is given by an alternating Taylor series, the approximation error made when truncating the series is determined by its final term.  The error is less than that of the final term.  A pretty efficient algorithm in Python to calculate sin follows.
def sin(x):
    epsilon = 0.1e-16
    sinus = 0.0
    sign = 1
    term = x
    n = 1
    while term > epsilon:
        sinus += sign*term
        sign = -sign
        term *= x * x / (n+1) / (n+2)
        n += 2
    return sinus

About one term is needed per digit of accuracy.  Note that the angle $x$ is given in terms of the fraction of circumference of a circle that subtends it, in English that means that since $360^\circ = 2\pi$ is a full circle, then $45^\circ = \pi/2$ radians.
Take care when using this code since it will not work as it stands when $term < 0$, so keep $x$ positive. It works well when $0 \leq x \leq 2\pi$.
Adding the following four lines directly after def sin(x): makes the code more robust.
    while x < 0:
        x += 2*pi
    while x > 2*pi:
        x -= 2*pi

A: The Maclaurin series of sine is
\begin{align*}
\sin x & =\lim_{n\rightarrow \infty}\left(x-\frac{x^3 }{3!}+\frac{x^5 }{5!}-\frac{x^7 }{7!}+\ldots+(-1)^n\frac{x^{2n+1} }{(2n+1)!}\right) \\ &= \sum_{n=0}^\infty (-1)^n\frac{x^{2n+1} }{(2n+1)!}.
\end{align*}
Read more here.
