for this problem I ju

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 20PE
icon
Related questions
Question

I have the question and the answer for this problem I just want to understand the concepts and logic of how to do it step by step

 

LUsing Taylor's thearem, we can obtain a formula to calculate he sine of S
sin(x) - x
- + (-1)
(2n - 1)!
Write a function detinition to calculate the sine of x using the formula above. Your function should
teminate when the absolute value of the last term calculated is less than 1.0 x 10. You may not use any
functions supplied in the cmath.h header file (ie. you cannor use the powx.y) function Your sine
function may call other functions, and in this case, you must also wrie the definitions of those functions.
You do nor need to comment anything, although, a well-placed comment may provide clarity for the
grader.
Bonus (2 pes): Briefly explain why the sine function above will always converge. You will only get the
bonus points if the sine function is wrimen.
Single Function Version
Multiple Function Version
double sin(double x) (
int i;
int n- 1
int sign;
double eps - 1.De-4;
double sum- 0.0;
double pow;
lang fact;
double this term;
do {
pow - 1.0;
Pact- 1
for (1-1; ie-2*n-1; +1) {
double sint double x) (
int a- 1;
double eps - 1.0e-4;
double sum - 0.0;
double this tera
do
this tern-sign(n-1)"pow(x, 2"a-
1)/fact(2'n-1):
sum this tern;
ir (this tern <0.0) this tern -
-this term;
*n;
} while (this tern eps);
return sum;
pow x;
fact i
ir ((n-aa - 1)
sign --1;
else
sign - 1;
this tern- sign'pow/fact;
int sign(int n) {
if (ns2 -- 1)
return -1
return 1;
sum - this_term;
if (this_ter < 0.0)
this tern --this term
double powdouble K, int a) {
int A
double p- 1.0
for (i-0; ien; **1)
} while (this tera eps):
Feturn sim;
P- x;
return p:
lang fact (int n) {
int i;
long f-1
for (1-1; ien; 1) {
return f
Transcribed Image Text:LUsing Taylor's thearem, we can obtain a formula to calculate he sine of S sin(x) - x - + (-1) (2n - 1)! Write a function detinition to calculate the sine of x using the formula above. Your function should teminate when the absolute value of the last term calculated is less than 1.0 x 10. You may not use any functions supplied in the cmath.h header file (ie. you cannor use the powx.y) function Your sine function may call other functions, and in this case, you must also wrie the definitions of those functions. You do nor need to comment anything, although, a well-placed comment may provide clarity for the grader. Bonus (2 pes): Briefly explain why the sine function above will always converge. You will only get the bonus points if the sine function is wrimen. Single Function Version Multiple Function Version double sin(double x) ( int i; int n- 1 int sign; double eps - 1.De-4; double sum- 0.0; double pow; lang fact; double this term; do { pow - 1.0; Pact- 1 for (1-1; ie-2*n-1; +1) { double sint double x) ( int a- 1; double eps - 1.0e-4; double sum - 0.0; double this tera do this tern-sign(n-1)"pow(x, 2"a- 1)/fact(2'n-1): sum this tern; ir (this tern <0.0) this tern - -this term; *n; } while (this tern eps); return sum; pow x; fact i ir ((n-aa - 1) sign --1; else sign - 1; this tern- sign'pow/fact; int sign(int n) { if (ns2 -- 1) return -1 return 1; sum - this_term; if (this_ter < 0.0) this tern --this term double powdouble K, int a) { int A double p- 1.0 for (i-0; ien; **1) } while (this tera eps): Feturn sim; P- x; return p: lang fact (int n) { int i; long f-1 for (1-1; ien; 1) { return f
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
LUP Decomposition
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
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
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage