Taylor Series for sine function
Show older comments
I'm trying to code the sine function using the taylor series with x_0 dependent on x, and -10 <= x <= 10; however, I'm kind of stuck on how to do it. I'm trying to code using only basic operations and the modulo function. What I'm mainly having trouble with is coding the trig identities within my function. For example,
sin(x + pi/2) = cos(x)
cos(x + pi/2) = -sin(x)
Anyone have any helpful tips for trying to switch the cosine and sine values at a particular x, without using a transcedental function, or how to go about coding sine in general that may help relieve me of my problem with the trig identities?
5 Comments
Walter Roberson
on 1 Oct 2018
You would not normally use mod() for taylor series.
Are you trying to do "argument reduction" to take an arbitrary angle and move it into a defined range where you can be more accurate?
If you are operating numerically, then for large angles, using mod() can end up being rather inaccurate
tsmart15
on 1 Oct 2018
John D'Errico
on 1 Oct 2018
Edited: John D'Errico
on 1 Oct 2018
Actually, mod works very nicely for a trig Taylor series, though it may not go as far as you want. It gets you into a reasonable start point though, and then you can do further range reduction as desired.
Of course, mod does not apply for all Taylor series. But for trig functions, it is quite convenient, since you can use the periodicity of those functions to your gain.
Walter Roberson
on 1 Oct 2018
mod() isn't going to work for numeric arguments beyond about 3.7E16, by which point eps(x) is greater than 2*pi
John D'Errico
on 1 Oct 2018
Edited: Walter Roberson
on 1 Oct 2018
Yes, that is very true. But the range here was expressly [-10,10], where mod works just fine for range reduction. Anyway, to compute the sin of numbers that large requires some very careful code written.
Accepted Answer
More Answers (0)
Categories
Find more on Number Theory in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!