Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Calculate the Cosine and Sine of this angle using the Taylor Series given below:

ID: 3881683 • Letter: C

Question

Calculate the Cosine and Sine of this angle using the Taylor Series given below:

Sine(x) = x – x3/3! + x5/5! – x7/7! + x9/9! – x11/11! + ………

Cosine(x) = 1 – x2/2! + x4/4! – x6/6! + x8/8! – x10/10! + ………

The variable x is in radians and not degrees.

Other trigonometric functions can be calculated using:

Tangent(x) = Sine(x)/Cosine(x)

CoSecant(x)    = 1.0/Cosine(x)

You should use a while loop for this series. You will terminate the loop when the difference between previous and current calculated values is equal to or less than 0.0001.

You should test your functions using radians

To calculate the factorial of a number use a function called factorial(x). This function should take a double as a parameter and return a double as value. The factorial should be calculated using a “for” loop.

Note: All function variables and functions return types should be doubles.

(1) Create a function to calculate the taylor series of a sine of angle. You will call your function mySine().

(2) Create a function to calculate the taylor series of a cosine of angle. You will call your function myCosine().

(3) Ceatea function to calculate the cotangent of an angle. You will call your function myCotangent().

(4) Create a function to calculate the secant of an angle. You will call your function mySecant().

Using C++ each program is separate from eachother

Explanation / Answer

Program:

#include <iostream>
#include <math.h>

using namespace std;

double fact(double x)
{
double fac=1;
for(double i=1;i<=x;i++)
{
fac = fac*i;
}
return fac;
}
double mySine(double x)
{
double sine;
double prevValue = x;
double currentValue = x;
double i =3;
double sign = -1;
do
{
currentValue = (sign)*pow(x,i)/fact(i);
prevValue = prevValue + currentValue;
i=i+2;
sign=-1*sign;
}while(prevValue - currentValue>=0.0001);
  
sine = prevValue;
return sine;
}

double myCosine(double x)
{
double cosine;
double prevValue = x;
double currentValue = x;
double i =2;
double sign = -1;
do
{
currentValue = (sign)*pow(x,i)/fact(i);
prevValue = prevValue + currentValue;
i=i+2;
sign=-1*sign;
}while(prevValue - currentValue>=0.0001);
  
cosine = prevValue;
return cosine;
}

double myCotangent(double x)
{
double cotangent = (double)(myCosine(x)/mySine(x));
return cotangent;
}

double mySecant(double x)
{
double sec = (double)(1/myCosine(x));
return sec;
}
int main()
{
double angle;
cout<<"Please enter an angle: ";
cin>>angle;

double sine = mySine(angle);
double cosine = myCosine(angle);
double cotangent = myCotangent(angle);
double sec = mySecant(angle);

cout<<"Sine of the angle is: "<<sine<<endl;
cout<<"Cosine of the angle is: "<<cosine<<endl;
cout<<"Cotangent of the angle is: "<<cotangent<<endl;
cout<<"Sec of the angle is: "<<sec<<endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote