Description
EECS 2510 : Nonlinear Data Structures
Description:
In your first project you will use Simpson’s rule to determine the integral of a function over an interval.
The user will input a lower value for x (a), an upper value for x (b), and a number of steps that should
be used to compute the step size, h. Your program will compute the integral over the range using the
given step size and report the value. Your intermediate data will be output in a table.
Details:
Simpson’s ⅜ rule allows us to approximate a value for a function. If the function were sin(x) where x is
in radians and our lower value was 0.0, our upper value is 3.14159, and a step size of h of 0.1570795.
Simpson’s rule finds the integral over this interval as:
Simpson’s 3/8 Rule — Sample Calculation for f(x) = sin(x)
h 0.1570795
a b = a + h f(a)
f((2a +
b)/3)
f((a+2*b)/
3) f(b)
value = (b-a)/8 * (f(a) + 3 * f((2a+b)/3) + 3 * f((a + 2 *
b)/3) + f(b))
0.00000 0.15708 0.00000 0.05234 0.10453 0.15643 0.01231
0.15708 0.31416 0.15643 0.20791 0.25882 0.30902 0.03663
0.31416 0.47124 0.30902 0.35837 0.40674 0.45399 0.06005
0.47124 0.62832 0.45399 0.50000 0.54464 0.58778 0.08199
0.62832 0.78540 0.58778 0.62932 0.66913 0.70711 0.10191
0.78540 0.94248 0.70711 0.74314 0.77715 0.80902 0.11932
0.94248 1.09956 0.80902 0.83867 0.86602 0.89101 0.13379
1.09956 1.25664 0.89101 0.91355 0.93358 0.95106 0.14497
1.25664 1.41372 0.95106 0.96593 0.97815 0.98769 0.15258
1.41372 1.57080 0.98769 0.99452 0.99863 1.00000 0.15643
1.57080 1.72787 1.00000 0.99863 0.99452 0.98769 0.15643
1.72787 1.88495 0.98769 0.97815 0.96593 0.95106 0.15258
1.88495 2.04203 0.95106 0.93358 0.91355 0.89101 0.14497
2.04203 2.19911 0.89101 0.86603 0.83867 0.80902 0.13379
2.19911 2.35619 0.80902 0.77715 0.74315 0.70711 0.11932
2.35619 2.51327 0.70711 0.66913 0.62932 0.58779 0.10191
2.51327 2.67035 0.58779 0.54464 0.50000 0.45399 0.08199
2.67035 2.82743 0.45399 0.40674 0.35837 0.30902 0.06005
2.82743 2.98451 0.30902 0.25882 0.20791 0.15644 0.03663
2.98451 3.14159 0.15644 0.10453 0.05234 0.00000 0.01231
2.00000
Your program should allow the user to put in the starting value (a), the ending value (b), and the
number of steps to do (in this case we have 20 steps). The step size above is (b-a)/20. It should then
calculate the values and for each interval it should output the values of a, b, and Simpson’s ⅜ rule for
each interval. At the end, the total of the values should be reported and your program should exit.
EECS 2510: Project 1 1 Spring 2018
Hints and Advice:
Do it in little pieces. Do the input of the values and make sure they are coming in the way you expect
first. Compute the value for one small interval and test it. You can use the data in the table above to
help you test it. Finally, start doing all the intervals and compute the sum.
Submission:
Your source files (.cpp, .h, .hpp) should be submitted online in BlackBoard. I need only your source
files. You do not need to zip them together to submit them.
EECS 2510: Project 1 2 Spring 2018