Question: Write a complete C++ program that does the following. and please include the comments to explain what you did. thankyou! Write a program to demonstrate

Write a complete C++ program that does the following. and please include the comments to explain what you did. thankyou!

Write a complete C++ program that does the following. and please include

Write a program to demonstrate that the derivative of the sine function is the cosine function. The derivative of a function gives you the slope of the function, and (if you haven't had calculus yet), the slope of the sine(x) is equal to the cosine(x). So to do this, we'll generate 100 values of sin(x) and cos(x) for x between 0 & 2 PI, then calculate the slope ofthe sine values and see how close they are to the cosine values. You'll need several arrays of doubles, length 100 forthis. Use C++'s sin(), cos(), abs(), min() and max() for this exercise. The sample program sample trig-cpp will help with this part of the assignment. Assignment 2 1) Generate 100 x-values between 0 & 2 PI. Use the following code (Put define USE MATH DEFINES at the top of your program, before you tinclude any header files.) double x [100] double delta 0*M PI /100.0 for int i 0; i 100; i++) x ij delta. 2) Calculate sin(x) and cos(x), and store them in 2 arrays, sines [100] and cosines [100]. 3) Estimate the cos(x) by calculating the slope of the sin(x). For each value of x, use the slope from the previous point to the next point: est cos [i] (sines litij siness [i-1]) (2*delta. note: for i 0, use the last sines value as the previous point, and for i 99, use the first sines value as the next point. 4) Calculate the difference between your cosine estimates and your calculated cosines, 5) Find and print out the maximum and minimum absolute difference. Le, use abs() to get the absolute value ofthe differences, and find the largest and smallest of these using max and min Note: if you use doubles your differences should be very small. You might need to do cout scientific setprecision (4) cout setw (8) diffs li You can do this with 3 loops In the first loop, do steps 1 and 2 above o calculate X sineslij and cosineslil In the second loop, calculate the slopes and differences o calculate slopeslil and diffsli] In the third loop, find the largest and smallest differences o hint: start by setting maxdiff abs(diffs[0]) and then loop with i from 1 to 99 and set maxdiffto max(maxdiff, abs(diffsliD), and do the same for mindiff

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!