Trignometry With Pure Python
Discovered by 7th century mathematician Bhaskara I, this formula is elegant and simpler than the next method that I am gonna discuss. While it does not give the perfect value, it is still a very good approximation
The graphs of sin x and the approximation formula are visually indistinguishable and are nearly identical.
angle = 30def sin(x): return ( 4*x*(180-x) ) / ( 40500 - x *(180-x) )def cos(x): return sin(90 - x)def tan(x): return sin(x) / cos(x)
So lets say you have a robot that can draw any function you want but its kinda like AI and gets better with more functions we feed it. The “sine” is a function that goes infinitely up and down. But the robot doesn’t know how to draw the sine curve directly.
So to teach it how to draw a complex curve, we give it a set of simpler instructions called the Taylor Series
. These instructions tell robot how to draw a bunch of smaller, simpler curves called “polynomials.”
Each polynomial is like a tiny part of the sine curve. The more polynomials we use, the more accurate our drawing becomes. It’s like putting together puzzle pieces to make a bigger picture.
Eventually there will be a point where there would be enough polynomials to make the robots drawing almost identical to the actual sine curve
pi = 3.14592653589793238462643383279502def f(n): # Factorial Function if n == 1 or n == 0: return 1 else: return n * f(n - 1)
def deg(x): # convert deg to radians rad = x * pi/180 return rad
def sin(x): # Taylor Expansion of sinx x = deg(x) k = 0 sinx = 0 while x >= pi: x -= pi if pi > x > pi / 2: x = pi - x while k < 15: sinx += (-1)**k * x**(2*k + 1) / f(2*k + 1) k += 1 return sinx
Namish
( っ˶´ ˘ `)っ made out of ❤️ and boredom
built with astro