Question: Write a program in C computer-programming language using one or more iteration structures to approximate the cosine function, given a radian value x, input using
Write a program in C computer-programming language using one or more iteration structures to approximate the cosine function, given a radian value x, input using scanf() During each iteration of the summation shown above, use printf() to output the value of the iteration index k, the kth approximation of cos(x), and the kth approximation error
errork = cosk (x)cosstdlib (x).
To use the standard library cosine function, you must include the math header file:
Recall the factorial of a nonnegative integer n is defined as n!=n*(n1)*(n2)* ... 10!=1 You can implement the factorial evaluation using a while() construct. The
calculates xy. The fabs() function calculates the absolute value of floating-point number,
Example output:
$ ./Lab03.exe ? 3.14 k: 0, cos(x): 1.000000, err: 1.999999e+00 k: 1, cos(x): -3.929800, err: 2.929802e+00 k: 2, cos(x): 0.120688, err: 1.120687e+00 k: 3, cos(x): -1.210518, err: 2.105196e-01
function Modify your program so you store the error computed during the previous iteration and stop iterating when the previous error equals the current iteration error. In your comment block header explain how many iterations were invoked for x = , /2, /3, and /4, for a reasonableapproximate value of .




The Maclaurin series expansion for cos(x) is the infinite alternating series cos(x)=1-- + 2!' 4! 6! -o (2k)! Write a program using one or more iteration structures to approximate the cosine function, given a radian value x, input using scanf(). We will be discussing iteration in class on Thursday February 6, but in the meantime read sections 3.7 to 3.12 in the textbook. During each iteration of the summation shown above, use printf() to output the value of the iteration index k, the kth approximation of cos(x), and the kth approximation error error, = |cos, (x) - cos stdlib (x) where cosk(x) refers to the kth iteration approximation and CoSstdlib(x) is the value returned by the C standard library cosine function. To use the standard library cosine function, you must include the math header file: #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
