Cody

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

Solution 992732

Submitted on 4 Oct 2016 by Giovanni Mottola
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
deltax = pi/12; Fx = cos(linspace(0,pi/2,7)); y_correct = 1.00002631217059; tol = 1e-14; assert(abs(simpsInt(Fx,deltax) - y_correct) < tol)

2   Pass
deltax = 0.125; Fx = exp((0:8)/8); y_correct = 1.7182841546999; tol = 1e-14; assert(abs(simpsInt(Fx,deltax) - y_correct) < tol)

3   Pass
deltax = 1; Fx = (0:10).^2; y_correct = 1000/3; tol = 1e-11; assert(abs(simpsInt(Fx,deltax) - y_correct) < tol)

4   Pass
deltax = 1; Fx = (0:10).^4; y_correct = 20001.3333333333333; tol = 1e-9; assert(abs(simpsInt(Fx,deltax) - y_correct) < tol)

5   Pass
deltax = 1; Fx = sin(-5:5); y_correct = 0; tol = 1e-15; assert(abs(simpsInt(Fx,deltax) - y_correct) < tol)

6   Pass
deltax = 0.25; Fx = sin(0:.25:100); y_correct = 0.13768413796203; tol = 1e-15; assert(abs(simpsInt(Fx,deltax) - y_correct) < tol)

7   Pass
deltax = 1; Fx = double((0:10) >= 5); y_correct = 5.66666666666667; tol = 1e-14; abs(simpsInt(Fx,deltax) - y_correct) < tol

ans = logical 1

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!