Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program must be in C For this program, lets explore some of the ways we can use C to perform numerical integration.Well restrict our attention

Program must be in C

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

With the rectangle rule, if we wish to calculate the area under a curve between two end points, a and b, we can evaluate the function at the midpoint between a and b and use that value to create a rectangle whose area will approximate the area under the curve between a and b. A diagram follows:

image text in transcribed

Here, the area of the red rectangle is consider an approximation for the definite integral between a and b. This area can be expressed by the following equation:

image text in transcribed

When this technique is applied to a larger region of the curve, we can divide the whole large region into smaller sub-regions of equal size, and apply the rectangle rule to each one. We may get something like the following:

image text in transcribed

An approximation for the definite integral between, say, -2 and 2, in this case, will then be the sum of the areas of the rectangles. That sum will produce an approximation for the integral over the entire region.

With the trapezoidal rule, we can do something similar. The difference is that trapezoids instead of rectangles are used to create the underlying approximation. Here is a diagram:

The area of the trapezoid (and therefore an approximation of the area under the curve) is given by the following equation:

image text in transcribed

When applied to a larger region that is divided into many sub-regions, we get something like:

image text in transcribed

Here the technique is very similar: We divide the total region to be integrated into smaller sub- regions of equal size, calculate area of the trapezoid for each region, and then sum them all up to produce an approximation for the whole integral.

Assignment

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

At the minimum, your program should have separate functions for: (a) the calculation of a single rectangle; (b) the calculation of a single trapezoid; and (c) the calculation of f(x) for some x. (Of course, writing other functions for specific tasks is always encouraged.)

Initial Settings and Specifications

For our initial values, lets let NUM_INTERVALS = 100, and f(x) = x3 - 3x2 + 2. A diagram of that curve is depicted below. There are several opportunities to integrate that curve within [~0.3, ~2.3]. Have the computer ask the user which method he would like to use to do the integration, i.e., rectangle or trapezoid, and then to specify the endpoints. Your program will then return the result of the integral approximation based on the indicated method.

? f((a + b) /2) f(x) (a + b)/2 ? f((a + b) /2) f(x) (a + b)/2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions