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

You\'ll need to do some work by hand to know what kind of results to expect. Beg

ID: 3694504 • Letter: Y

Question

You'll need to do some work by hand to know what kind of results to expect. Begin with this Analytical Work Worksheet (distributed in class).

Do the following:

Compute the definite integral of f(x) on the interval [a, b], showing your work. (We want the general case, not the specific case above.)

Find x coordinates that divide the given interval up into 10 subintervals. (There should be 11.) Make a sorted table with x and f(x) for the left and right bounds of interval and the 9 points that divide the interval up.

Using the first graph, plot the points to divide the interval up into 5 subintervals (using the points in the shaded columns in the table in the worksheet). Then draw the 5 rectangles or trapezoids that would be used in approximate the integral of f(x) for this curve for your assigned quadrature method. Shade the area that would be erroneous in this approximation.

Repeat step (d), but use 10 rectangles this time (all points in your data table).

Hopefully, you now have a visual idea of what's going on with your quadrature technique and what you'll be programming, as well as what kind of results to expect.

Function 1: Function to Integrate

Now, begin a new program and create a function that implements f(x) as defined above.

Function 2: Area of an Interval

Create a second function that has as input parameters the left and right bounds of an interval.

This function should return the area of the interval between the given bounds according to whatever quadrature technique you were assigned. Hardcode a call to the f(x) function.

Function 3: Quadrature Function

Create a function for your assigned quadrature technique to approximate the area under a curve.

Your function must have the following as parameters:

the left and right bounds of interval whose area under the curve we're approximating

the number of intervals to use for the approximation

The method should, of course, compute the approximation of the area under f(x) (or the function passed in if you generalize and do that) between the given bounds and return it (and thus should produce no screen output).

MUST BE DONE IN C++

Explanation / Answer

#include <iostream>
#include <cmath>
using namespace std;

using std::cin;
using std::cout;
using std::endl;

double func_1(double);
double func_2(double);
double func_3(double);
double func_4(double);
double func_5(double);
double rect_integral(double a, double b, int n, int choice);
double trap_integral(double a, double b, int n, int choice);

const char * funcname[6] = {
"",
"5x^4 + 3x^3 - 10x + 2",
"x^2 - 10",
"40x + 5",
"x^3",
"20x^2 + 10x - 2" };

int main () {

int choice;
int n;
double a;
double b;
bool trap = false;
bool rect = false;

cout << "Functions available: ";
for (int i=1; i<6; i++)
cout << " " << i << " " << funcname[i] << ' ';
cout << endl;

cout << "Choose a function (1, 2, 3, 4, 5, other(quit)) " << endl;
cin >> choice;

if (choice >= 1 && choice <= 5)
{
char method = ' ';
do {
cout << "Would you like to calculate the area using the rectangle,"
<< " trapezoid, or both (1, 2, 3): " << endl;
cin >> method;
} while (method < '1' || method > '3');

switch (method) {
case '1':
rect = true;
cout <<"How many rectangles do you want? " << endl;
break;
case '2':
trap = true;
cout <<"How many trapezoids do you want? " << endl;
break;
case '3':
trap = true;
rect = true;
cout <<"How many rectangles/trapezoids do you want? " << endl;
}

cin >> n;

cout <<"Please select a starting point, a: " << endl;
cin >> a;

cout <<"Please select an ending point, b: " << endl;
cin >> b;

if (rect) {
cout << "The area under " << funcname[choice]
<< " between " << a << " and " << b
<< " is: " << rect_integral(a, b, n, choice) << endl;
}

if (trap) {
cout << "The area under " << funcname[choice]
<< " between " << a << " and " << b
<< " is: " << trap_integral(a, b, n, choice) << endl;
}
}

return 0;
}

double func_1 (double x)
{
return 5.0*x*x*x*x + 3.0*x*x*x - 10.0*x + 2.0;
}

double func_2 (double x)
{
return x*x - 10.0;
}

double func_3 (double x)
{
return 40.0*x + 5;
}

double func_4 (double x)
{
return x*x*x;
}

double func_5 (double x)
{
return 20.0*x*x + 10.0*x - 2.0;
}

double rect_integral(double a, double b, int n, int choice)
{


// here insert the code to calculate the integral
return 1.0; // dummy value
}

double trap_integral(double a, double b, int n, int choice)
{
// here insert the code to calculate the integral
return 2.0; // dummy value
}

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