How to calculate Sin function quicker and more precisely?
Posted
by
user1297181
on Programmers
See other posts from Programmers
or by user1297181
Published on 2012-10-08T13:06:17Z
Indexed on
2012/10/09
3:50 UTC
Read the original article
Hit count: 257
c++
|algorithms
I want to calculate y(n)=32677Sin(45/1024•n)
, where y
is an integer and n
ranges from 0 to 2048. How can I make this process quicker and more precisely?
Now I want to show you a reference answer:
Since Sin(a+b)=Sin(a)Cos(b)+Cos(a)Sin(b)
And Cos(a+b)=Cos(a)Cos(b)-Sin(a)Cos(b)
.
So I can store Sin(45/1024•1) and
Cos(45/1024•1) ` only.Then use this formula:
Sin(45/1024•2)=Sin(45/1024•1+45/1024•1)
,
Cos(45/1024•2)=Cos(45/1024•1+45/1024•1)
,
....
`Sin(45/1024•n)=Sin(45/1024•(n-1)+45/1024•1) `,
`Cos(45/1024•n)=Cos(45/1024•(n-1)+45/1024•1) `,
This way maybe quicker without storing large array.
© Programmers or respective owner