Approximate values for sine and cosine of an angle, x (radians), can be obtained
ID: 3880917 • Letter: A
Question
Approximate values for sine and cosine of an angle, x (radians), can be obtained from the tollowing infinite series equations: sin x = x--+ + Eq. 1 5! cosx = 1--+ + Eq. 2 2 4 6! 1. Develop a procedure for iteratively determining values for sine and cosine using this relationship. Based on your algorithm, program a simultaneous solution to each equation in C or C++ to determine "sin x" and "cos x", then solve the Pythagorean Identity, sin x2 cos x2-1 , using your approximate values, for a given value ofx that is input by the user. Implement and run your program on the ULTRAVIOLET supercomputer. The results should display to screen in a tabular format. Include the % error obtained for the true value of 1.00000" 2.Explanation / Answer
Here is the solution, do give me a thumbs up if this helps!
#include <iostream>
#include<math.h>
using namespace std;
double fact(int x)
{
int j=1;
if(x==0 || x==1)
return 1;
else
{
for(int i=2;i<=x;i++)
j*=i;
}
return j;
}
int main() {
double sinx=0, cosx=0,x;
cin>>x;
int i;
for(i=0;i<10000;i++)
{
sinx+=pow(-1,i)*pow(x,2*i+1)/fact(2*i+1);
cosx+=pow(-1,i)*pow(x,2*i)/fact(2*i);
}
cout<<sinx<<endl<<cosx;
cout<<pow(sinx,2)+pow(cosx,2);
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.