Question: 2 Numerical Integration (70 pts) Numerical integration is often used when one wants to compute b f (x)dx but one does not know how to

2 Numerical Integration (70 pts)

Numerical integration is often used when one wants to compute b f (x)dx but one does not know how to find a

a primitive of f. You can use the definition of integration to obtain a simple approximation by computing ba n1 f a + (i + .5) ba . n is often called the number of point in the approximation. (This is the

ni=0 n numerical integration using the rectangle rule. You can learn more at https://en.wikipedia.org/wiki/

Numerical_integration.) Note that you do not need to understand numerical integration. The problem is just to evaluate

ba n1 f a + (i + .5) ba for a particular combination of a, b, n, and f . ni=0 n

The provided package contains multiple functions to integrate in libfunctions.a. The functions are named f1, f2, f3, f4, and take two parameters: the first one is a floating point number x where the function is computed, and the second one is intensity an operation intensity. The second parameter is used to make the function take more time.

The code you should write should take 5 command line parameters: functionid, an integer to know which function to integrate. If functionid is 1, integrate f1 a, the lower bound of the integral b, the upper bound of the integral n, an integer which is the number of points to compute the approximation of the integral intensity, an integer which is the second parameter to give the the function to integrate

1

The code should compute the integral and output the value of the integral on stdout (and nothing else). The code should also measure the time it took to compute the integral and write that time (expressed in seconds with decimal values) to stderr. Question: Write the described code. You can use the provided archive as a template. It contain a template code and makefile to help you write the code. You should only need to complete main.cpp. You should be able to test if your code is correct using make test.

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!