Taylor Series for sine function
이전 댓글 표시
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
Walter Roberson
2018년 10월 1일
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
2018년 10월 1일
John D'Errico
2018년 10월 1일
편집: John D'Errico
2018년 10월 1일
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
2018년 10월 1일
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
2018년 10월 1일
편집: Walter Roberson
2018년 10월 1일
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!