205k views
2 votes
g Implement the Taylor Series for the Sine function using a loop. The mySine() function compares the previous calculated Sine to the current calculated value of Sine. Once the difference between these two values is within the error (0.00001) indicated in the specification, the value should be returned to the calling function.

User Rugal
by
5.6k points

1 Answer

4 votes

Answer:

#include <iostream>

#include <cmath>

double mySine(double x);

double factorial (int f);

double sine(double x);

double cosine(double x);

const double PI = atan(1.0)*4.0;

using namespace std;

int main(){

double x= 0.0;

double angle_in_radians;

double angle_in_degrees;

angle_in_radians = angle_in_degrees * PI/180.0;

while (x < 0.7853){

x = x + 0.261799;

angle_in_degrees = x * (180/PI);

}

cout << endl;

double factorial(int x);

double f = 1.0;

for (int i = 1; i <= x; i++){

f = f * i;

}

return f;

}

double sine (double x){

double sum_positive = 0.0;

double sum_negative = 0.0;

double output = 0.0;

double angle_in_degrees;

for (int i = 1; i <= 1000; i += 4){

sum_positive = sum_positive + factorial (i);

}

for (int i = 3; i <= 1000; i += 4){

sum_negative = sum_negative + factorial (i);

}

output = (sum_positive - sum_negative);

return output;

return angle_in_degrees = x * (180/PI);

}

Explanation:

Implement the Taylor Series for the Sine function using a loop. The mySine() function compares the previous calculated Sine to the current calculated value of Sine. Once the difference between these two values is within the error (0.0001) indicated in the specification the value should be returned to the calling function.

Note: Make sure to create a function prototype for mySine() and place it above main()"

User Shihpeng
by
5.4k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.