Taylor Series for sine function
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 1 Ott 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
il 1 Ott 2018
John D'Errico
il 1 Ott 2018
Modificato: John D'Errico
il 1 Ott 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
il 1 Ott 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
il 1 Ott 2018
Modificato: Walter Roberson
il 1 Ott 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.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Number Theory in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!