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

Problem 1. Write a C program, called cos_approx.c, that computes theapproximate

ID: 3616906 • Letter: P

Question

Problem 1. Write a C program, called cos_approx.c, that computes theapproximate value of cos(x) according to its Taylor seriesexpansion: This series produces the exact value of cos(x) for any realnumber x, but contains an infinite number of terms. Obviously, acomputer program can compute only a finite number of terms. Thus,you will have to truncate the infinite series in (1). Your programshould be able to do so in two different ways. Fixed number of terms: Implement the function cos_N(double x,int N ) that accepts as parameters a real number x and an integer N(you can assume that N will be always positive). The functioncos_N should return the sum of the first N terms in(1), as a double. Fixed precision: Implement the function cos_delta(double x,double delta) that accepts as parameters a real number x andanother real number (you can assume that will bealways positive). The function cos_delta should return, as adouble, the sum of the first N terms in (1), where N is thesmallest positive integer such that Notice that the first sum in(2) contains N terms, while thesecond sum contains N-1 terms. It is possible for the second sum in(2) to be empty- this happens when N =1. You should assume that anempty sum evaluates to zero. 5 1 -1.00 6 2 1 0.00001 1 1.5         2 2 2 0.09 2 2 1.1 The program should write its output to the filecos_output.dat. The output file should consist of m lines, one pertest case. For each test case, the program should print thetest-case number followed by cos(x.xxx) = y.yyyyyyyyyyyy. In the above, the argument ofcos(.) should be printed with 3 digits of precision, while its(approximate) value should be printed with 12 digits of precision.For example, here is the file cos_output.dat that results uponprocessing the file cos_input.dat above: Case 1: cos(-1.000) = 0.540302303792 Case 2: cos(1.000) = 0.540302303792 Case 3: cos(1.500) = -0.125000000000 Case 4: cos(2.000) = -0.422222222222 Case 5: cos(2.000) = 1.000000000000 Notes: You are not allowed to use any functions declared in<math.h> in the file cos_appro.c that you submit. However, itmight be advisable to use standard-libray functions such aspow(x,y) and cos(x) during the development and debugging of theprogram, in order to compare their output with the output of thefunctions that you implement. If you choose to do so, do not forgetto delete the relevant parts of the code in the final version ofcos_approx.c that you submit.

Explanation / Answer

please rate - thanks sorry I don't understand the math for the delta. but at least thiswill get you started #include #include #include using namespace std; double pow(double,int); int fact(int); double cos_N(double, int); double cos_delta(double,double); int main() {double x,cos,delta; long int i,ct,n; int num,type; ifstream in; ofstream out; in.open("cos_input.dat");          //open file if(in.fail())            //is it ok?    { coutnum; for(i=0;i>type; in>>x; if(type==1) {in>>n; cos=cos_N(x,n); } else {in>>delta; cos=cos_delta(x,delta); } out
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