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!