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

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

ID: 3864588 • Letter: W

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 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.

Explanation / Answer

// ConsoleApplication15.cpp : Defines the entry point for the console application.
#define _USE_MATH_DEFINES
#include <cmath>
#include <algorithm>
#include<iostream>
#include <iomanip>

using namespace std;
int main()

{
   //initialized five arrays of typr double and size 100
   double x[100] = {};
   double sines[100] = {};
   double cosines[100] = {};
   double est_cos[100] = {};
   double diff[100] = {};

   double delta = 2.0*M_PI / 100.0;
double   maxdiff =0;
   double mindiff = 0;


   for (int i = 0; i < 100; i++)
   {
       x[i] = i*delta;
       sines[i] = sin(x[i]);
       cosines[i] = cos(x[i]);


   }

   for (int i = 1; i < 99; i++)
   {
      
          
      

           est_cos[i] = (sines[i + 1] - sines[i - 1]) / (2 * delta);

           diff[i] = est_cos[i] - cosines[i]; //finding absolutes difference between estimated cos and actual cos
      
   }
   est_cos[0] = (sines[1] - sines[99]) / (2 * delta);
   diff[0] = est_cos[0] - cosines[0]; //finding absolutes difference between estimated cos and actual cos


   est_cos[99] = (sines[0] - sines[98]) / (2 * delta);
   diff[99] = est_cos[99] - cosines[99]; //finding absolutes difference between estimated cos and actual cos


  
   maxdiff = abs(diff[0]);
   mindiff = abs(diff[0]);
  
     
   for (int i = 1; i < 100; i++)
   {

       maxdiff = std::max(maxdiff, abs(diff[i]));
  

       mindiff = std::min(mindiff, abs(diff[i]));
   }

   cout << scientific << setprecision(4);
   cout << setw(8) << "minimum difference: " << mindiff << endl;
   cout << setw(8) << "maximum difference: " << maxdiff << endl;

return 0;
}

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