PROBLEM: Write a computer program which uses the trapezoidal rule to calculate t
ID: 3621518 • Letter: P
Question
PROBLEM:
Write a computer program which uses the trapezoidal rule to calculate the integral of a polynomial function. It should contain a function whose prototype will be:
double integratePoly(int polyOrder, double polyCoef[],double limit_a, double limit_b)
Within this function perform repeated calculations of the integral using the trapezoidal rule, until the difference between two calculations is sufficiently small (0.001). With every new calculation the number of intervals, n, is doubled.
At the top level, main(), the user should be able to direct the program by selecting from a menu of tasks:
1. entry of the polynomial function coefficients,
2. entry of the limits for integration,
3. integration of the polynomial between the entered limits
4. display of the polynomial.
5. display of the result of integrating the polynomial between the entered limits
6. quit the program.
SOLUTION:
1. Desk-check your algorithm with the test-case 1: (omit test case2)
3. Your main should display a menu asking the user to pick from a list of options: enter polynomial coefficients; enter the integration limits; display the polynomial; integrate the polynomial between the entered limits; display the results; or quit. It will be appropriate to use a switch-case branching structure, within a loop, in main() to organize the calling of your functions.
Explanation / Answer
Hope this helps. Let me know if you have any questions. Please rate. :) #include #include using namespace std; double calculate(int polyOrder, double polyCoef[], double x) { double result = 0; for (int i = 0; i .001 double I = 0; double newI = 0; bool flip = false; if (limit_a > limit_b) { flip = true; double temp = limit_a; limit_a = limit_b; limit_b = temp; } while (abs(dx) > .001) { n *= 2; double h = (limit_b - limit_a) / n; double sum = 0; double x = limit_a + h; // first calculate the limit_a value and limit_b value and divide each by 2 sum += calculate(polyOrder, polyCoef, limit_a) / 2; sum += calculate(polyOrder, polyCoef, limit_b) / 2; // then calculate all internal values which won't be divided by 2 while (xRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.