L 10 6 2 0 -2 -8 -20246 8 10 -10 -10-8-6-4-20 For the other arguments, use the periodicity of the sine or cosine function. sinx = 2 = 3! cosx = 1 – + 5! 7! n=0 (-1)" 2n+1 (2n+1)! (1) 2! 4! 6! n=0 (-1)"2n (2n)! (2)

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter10: Application Development
Section: Chapter Questions
Problem 6VE
icon
Related questions
Question

Write a program to calculate the function sin(x) or cos(x) using a Taylor series expansion around the point 0. In other words, you will program the sine or cosine function yourself, without using any existing solution. You can enter the angles in degrees or radians. The program must work for any input, e.g. -4500° or +8649°. The function will have two arguments:

float sinus(float radians, float epsilon);

For your own implementation, use one of the following relations (you only need to program either sine or cosine, you don't need both):

Tip 1:  Of course, you cannot calculate the sum of an infinite series indefinitely. You can see (if not, look in the program) that the terms keep getting smaller, so there will definitely be a situation where adding another term will not change the result in any way (see problem 1.3 – machine epsilon). However, you can end the calculation even earlier – when the result changes by less than epsilon (a pre-specified, sufficiently small number, e.g. 0.000001) in two consecutive iterations.

Tip 2: It is important to note that epsilon does not express the accuracy of the calculated approximation.

Tip 3: Be aware that the above series approximate well only around zero, which means that for larger input angles it will "stop working" (see the figure below - the larger the degree of the polynomial, the better the approximation).

 

L
10
6
2
0
-2
-8
-20246 8 10
-10
-10-8-6-4-20
For the other arguments, use the periodicity of the sine or cosine function.
Transcribed Image Text:L 10 6 2 0 -2 -8 -20246 8 10 -10 -10-8-6-4-20 For the other arguments, use the periodicity of the sine or cosine function.
sinx = 2 =
3!
cosx = 1 –
+
5!
7!
n=0
(-1)" 2n+1
(2n+1)!
(1)
2!
4!
6!
n=0
(-1)"2n
(2n)!
(2)
Transcribed Image Text:sinx = 2 = 3! cosx = 1 – + 5! 7! n=0 (-1)" 2n+1 (2n+1)! (1) 2! 4! 6! n=0 (-1)"2n (2n)! (2)
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Similar questions
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr