keisoku

Trapezoidal & Simpson's Rule Integration

Numerically integrate f(x) with both the trapezoidal and Simpson's rules, then compare the two approximations.

Input

Enter the integrand f(x), the interval [a, b] and the number of subintervals n to approximate the definite integral with both the trapezoidal and Simpson''s rules.

e.g. sin(x), x^2, exp(-x^2), 2x+1. You can use pi, e and functions like sin, cos, exp, log.

An even value is used for Simpson''s rule (odd inputs are rounded to the nearest even number).

Result

Simpson''s rule approximation

2.0000000108

∫ sin(x) dx over [0, 3.1415926536]

Trapezoidal rule

1.9998355039

Simpson''s rule

2.0000000108

Difference

0.0001645069

Approximation by method

MethodValue
Trapezoidal rule1.9998355039
Simpson''s rule2.0000000108

Computation parameters

Subintervals n (used)100
Step size h0.0314159265

How it works

  • The trapezoidal rule splits [a, b] into n equal subintervals and approximates each strip as a trapezoid. With step h=(b-a)/n, I≈h×(f0/2+f1+…+f(n-1)+fn/2).
  • Simpson's rule (the 1/3 rule) approximates each pair of subintervals by a parabola: I≈(h/3)×(f0+4f1+2f2+4f3+…+4f(n-1)+fn). Because n must be even, an odd input is rounded to the nearest even value.
  • For smooth functions Simpson's rule is generally more accurate and integrates cubic polynomials exactly. The difference between the two results is a rough indicator of the approximation error.
  • The integrand supports +, -, *, /, ^ (power), parentheses, unary minus and implicit multiplication, with the constants pi and e and the functions sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, log (=ln), log10, sqrt, cbrt and abs.
  • The bounds a and b may also be expressions containing pi or e. All computation runs in your browser with double-precision floating point and nothing is sent to a server.

Reviews

Tell us what you think of this calculator.

Write a review

  1. Home
  2. Trapezoidal & Simpson's Rule Integration