Question: INTRODUCTION For this program, lets explore some of the ways we can use C to perform numerical integration. Well restrict our attention to definite integrals

INTRODUCTION

For this program, lets explore some of the ways we can use C to perform numerical integration. Well restrict our attention to definite integrals on smooth curves only and look at two methods, called the rectangle rule and the trapezoidal rule respectively (http://en.wikipedia.org/wiki/Numerical_integration).

Lets write a C program that will calculate an approximate value for the definite integral of a curve using each of the two methods, the rectangle rule and the trapezoidal rule. Hopefully well be able to observe how the approximate value improves as we increase the number of subintervals (decrease the size of the sub-intervals).

Let us define these functions:

a) myFunc, which calculates a single value based on the underlying function that is being integrated. It basically returns f(x) for some input value x. As an illustration, we will set myFunc to be a polynomial function f(x) = x3 - 3x 2 + 2. Prototype is double myFunc(double x);

b) calcAreaRect, which calculates the area between two endpoints a1 and b1 using the rectangle method. This function will call myFunc. Prototype is double calcAreaRect(double a1, double b1);

c) calcAreaTrap, which calculates the area between two endpoints a1 and b1 using the trapezoidal method. This function will call myFunc. Prototype is double calcAreaTrap(double a1, double b1);

d) calcIntegral, which returns the approximation value between two end points, a and b, based on either the rectangle or trapezoidal method. calcIntegral will: (1) Divide the region between a and b into num_intervals subregions. (2) Calculate the approximate value for each sub-region according to the function calcAreaRect or calcAreaTrap. (3) Sum them all up to get the final result and return it. Prototype is double calcIntegral(int method, double a, double b, int num_intervals); // method = 1 indicates rectangle method, method = 2 indicates trapezoidal method

OUTLINE OF PROGRAM

Ask the user which method he/she would like to use to do the integration, i.e., rectangle or trapezoid, and then to specify the endpoints. Do input validation on the method. set num_intervals = 2 while (user has not selected to quit && num_intervals <= 128) calculate the integral based on the indicated method and the value num_intervals, and display the result ask if the user wants to quit num_intervals = num_intervals *2 print the exact value of the integral, calculated as g(b) g(a), where g(x) = x4 /4 x 3 + 2x for verification

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!