Post Reply 
Approximation of Sine function in Integer Forth
03-12-2022, 08:36 PM (This post was last modified: 03-12-2022 11:08 PM by Thomas Klemm.)
Post: #2
RE: Approximation of Sine function in Integer Forth
(03-12-2022 04:25 PM)Martin Hepperle Wrote:  Maybe there is another more elegant or more accurate approach?

You could use Bhaskara's Sine and Cosine Approximations.
They are accurate to about 1‰.

Functions in Python
Code:
def sin(x):
    u = (180 - x) * x
    return 4000 * u // (40500 - u)

def cos(x):
    u = x**2
    return 4000 * (8100 - u) // (32400 + u)

Plot the Difference
Code:
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 90, 91)

Sine
Code:
plt.plot(x, sin(x) -  1000 * np.sin(np.radians(x)), 'b')
[Image: attachment.php?aid=10454]

Cosine
Code:
plt.plot(x, cos(x) -  1000 * np.cos(np.radians(x)), 'r')
[Image: attachment.php?aid=10455]

Cheers
Thomas


Attached File(s) Thumbnail(s)
       
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Approximation of Sine function in Integer Forth - Thomas Klemm - 03-12-2022 08:36 PM



User(s) browsing this thread: 1 Guest(s)