Write your program so that it outputs the interval entered


Mathematical background:

Exact area under the curve created by function f(x) in interval [a,b] is given by:

Excat area = ab f(x)dx

For an interval divided into n equally spaced trapezoids, a = x1 < x2 < ... < xn+1 = b, where the grid spacing is h = (b-a)/n, the trapezoidal rule approximation to the integral becomes

approximate area = ab f(x)dx ≈ h/2 i=1Σn (f(xi+1)+ f(xi))

As the number of trapezoids increases the approximate result converges to the exact result.

Write a program which:

1. Prints out all of the required information for all assignments (see style sheet in D2L)

2. Which gets an interval from the user (i.e., values for a and for b). And gets the number n of trapezoids.

3. Has a function that calculates the exact integral over the interval ab for the cosine function

4. Has a function that calculates the area of a trapezoid given x1,y1 and x2,y2 (the other two points on the trapezoid can be assumed to be x1,0 and x2,0).

5. Has a function that calculates the area under the curve for the given interval of the cosine function using n trapezoids

6. Write your program so that it outputs the interval entered, the exact solution, the approximation, the number of trapezoids and the difference between the exact and approximate solutions.

7. Extra credit (up to an extra 2 points (where the rest of the assignment is worth 10 points) Your program should open a graphics window (629 x 201), fill it with white, draw the exact area in red and each trapezoid's borders in green, and then draw in the axes: Draw the x axis at y=100, draw the y axis at x=314, in black. Each pixel should represent 0.01. The graphics will be limited to an interval of no greater than -π to π. Note that instructors will give no assistance or advice on the extra credit until a working basic assignment is demonstrated to the instructor.


Attachment:- hw5 .rar

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Write your program so that it outputs the interval entered
Reference No:- TGS01125662

Now Priced at $65 (50% Discount)

Recommended (90%)

Rated (4.3/5)