Write a C program to compute the Maclaurin Series expansion of 𝑓(𝑥) = cos 𝑥.
You need to add the terms in the Maclaurin series until the percent relative error falls below a certain pre-specified relative error (%).
Inputs to your program will be x (in radians)) and the pre-specified relative error (%).
Your program should print the number of terms, cos x value obtained along with the true, absolute, and relative approximate errors (%).
Your program needs to get the true value of 𝑓(𝑥) = cos 𝑥 using the built-in cos 𝑥 function in C\C++.
Sample output:
Enter your approx. relative error bound:
0.001
Enter your angle in radians:
1.04719
N.terms Exact aproximate value absolute error relative error
1 0.500007 0.451697 0.048310 9.661871
2 0.500007 0.501803 0.001796 0.359220
......................
#include <iostream>
using namespace std;
int main()
{
int relative_error,angle;
cout<<"Enter your approx. relative error bound:"<<endl;
cin>>relative_error;
cout<<"Enter your angle in radians"<<endl;
cin>>angle;
return 0;
}
Comments
Leave a comment