Problem 43003. Simpsons's rule (but not Homer Simpson)

I wonder what Homer Simpson would have thought of Simpson's rule? Somehow I doubt his thoughts would have included the phrase Newton-Cotes, or even numerical integration.

In this problem, I want you to use Simpson's rule to integrate a function, provided as a list of points in a vector. The points must be equally spaced in x, so all that need be provided is the spacing between points in x. As well, I'll be nice and always give you an odd number of points, since that is important for Simpson's rule to work smoothly.

As a test case, we should know that the integral of cos(x) over the interval [0,pi/2] is 1, at least analytically that is true. Your Simpson's rule code, for only 7 points spanning that interval will do pretty well:

deltax = pi/12;
Fx = cos(linspace(0,pi/2,7));
simpsInt(Fx,deltax)
ans =
          1.00002631217059

Thus, Fx is a vector of supplied function values, and deltax is the step size taken on the x-axis.

Homer would be proud.

Solution Stats

35.77% Correct | 64.23% Incorrect
Last Solution submitted on Aug 22, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers36

Suggested Problems

More from this Author4

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!