Rectangle method

Rectangle method

In mathematics, specifically in integral calculus, the rectangle method (also called the midpoint or mid-ordinate rule) computes an approximation to a definite integral, made by finding the area of a collection of rectangles whose heights are determined by the values of the function.

Specifically, the interval (a,b) over which the function is to be integrated is divided into N equal subintervals of length h = (ba) / N. The rectangles are then drawn so that either their left or right corners, or the middle of their top line lies on the graph of the function, with bases running along the x-axis. The approximation to the integral is then calculated by adding up the areas (base multiplied by height) of the N rectangles, giving the formula:

\int_a^b f(x)\,dx \approx h \sum_{n=0}^{N-1} f(x_{n})

where h = (ba) / N and xn = a + nh.

The formula for xn above gives xn for the Top-left corner approximation.

As N gets larger, this approximation gets more accurate. In fact, this computation is the spirit of the definition of the Riemann integral and the limit of this approximation as n \to \infty is defined and equal to the integral of f on (a,b) if this Riemann integral is defined. Note that this is true regardless of which i' is used, however the midpoint approximation tends to be more accurate for finite n.

The different rectangle approximations
Top-left corner approximation  
Midpoint approximation  
Top-right corner approximation  

Contents

Error

For a function f which is twice differentiable, the approximation error in each section (a,a + Δ) of the midpoint rule decays as the cube of the width of the rectangle. (For a derivation based on a Taylor approximation, see Midpoint method)

E_i \le \frac{\Delta^3}{24}\,f''(\xi)

for some ξ in (a,a + Δ). Summing this, the approximation error for n intervals with width Δ is less than or equal to

n = 1,2,3,...

where n + 1 is the number of nodes

E \le \frac{n\Delta^3}{24}f''(\xi)

in terms of the total interval, we know that nΔ = ba so we can rewrite the expression:

E \le \frac{(b-a)\Delta^2}{24}f''(\xi)

for some ξ in (a,b).

Matlab Example Program

 
function [F] = rectangle( a, b, n )
 
%*******************************************************
 
% This function computes an approximation to a definite
% integral using rectangle method. Input variables are
% a=initial value, b=end value, n=number of iterations.
% Author: User:Gulmammad
% Modified: User:fOx
% Modified: User:cholericfun
 
%*******************************************************
 
h = ( b - a ) / n ;
 
F = 0 ;
 
 
% x = [0 , h*[1 : n-1]];          % for the left corner:  O(h)
  x = [a+.5*h,a+.5*h+h*[1:n-1]];      % for the center:       O(h²)
% x = [1:n]*h;                    % for the right corner: O(h)
 
for i = 1 : n
 
    F = F + f( x(i) ) * h ;
 
end
 
 
function [func] = f( x )
 
        func = 3 * x.^2 ; %specify your function here
 
    end
 
 
end

C example program

#include <stdio.h>
#include <math.h>
 
double f(double x){
   return sin(x);
}
 
double rectangle_integrate(double a, double b, int subintervals, double (*function)(double) ){
   double result;
   double interval;
   int i;
 
   interval=(b-a)/subintervals;
   result=0;
 
   for(i=1;i<=subintervals;i++){
      result+=function(a+interval*(i-0.5));
   }
   result*=interval;
 
   return result;
}
 
int main(void){
   double integral;
   integral=rectangle_integrate(0,2,100,f);
   printf("The value of the integral is: %f \n",integral);
   return 0;
}

Fortran Example Program

PROGRAM Calc
   IMPLICIT NONE
   DOUBLE PRECISION y, a, b, dx, xi
   INTEGER n, i
   DATA y /0.0d0/
 
   PRINT*, 'Enter the start, end and numer of intervals:'
   READ*, a, b, n
 
   dx = (b-a)/n
 
   DO i = 1, n
      xi = a + (i-0.5d0)*dx
      y = y + f(xi)*dx
   END DO
 
   PRINT*, 'Quadrature of f(x):', y
 
CONTAINS
 
   FUNCTION f(x)
      DOUBLE PRECISION f, x
      f = 4.0d0/(1.0d0 + x**2)
   END FUNCTION F
 
END PROGRAM Calc

See also


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • Method overriding — Method overriding, in object oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. The… …   Wikipedia

  • Method of exhaustion — This article is about the method of finding the area of a shape using limits. For the method of proof, see Proof by exhaustion. The method of exhaustion (methodus exhaustionibus, or méthode des anciens) is a method of finding the area of a shape… …   Wikipedia

  • Method of analytic tableaux — A graphical representation of a partially built propositional tableau In proof theory, the semantic tableau (or truth tree) is a decision procedure for sentential and related logics, and a proof procedure for formulas of first order logic. The… …   Wikipedia

  • Midpoint method — For the midpoint rule in numerical quadrature, see rectangle method. Illustration of the midpoint method assuming that yn equals the exact value y(tn). The midpoint method computes yn + 1 …   Wikipedia

  • Four Square Writing Method — The Four Square Writing Method is a framework for teaching essay writing to children in school. A number of books about this method were published by Judith Gould. It is taught primarily to students in grades 1 3, and to a lesser extent to… …   Wikipedia

  • Minimum bounding rectangle — The minimum bounding rectangle (MBR), also known as bounding box or envelope, is an expression of the maximum extents of a 2 dimensional object (e.g. point, line, polygon) within its 2 D (x, y) coordinate system, in other words min(x), max(x),… …   Wikipedia

  • Integral — This article is about the concept of integrals in calculus. For the set of numbers, see integer. For other uses, see Integral (disambiguation). A definite integral of a function can be represented as the signed area of the region bounded by its… …   Wikipedia

  • List of mathematics articles (R) — NOTOC R R. A. Fisher Lectureship Rabdology Rabin automaton Rabin signature algorithm Rabinovich Fabrikant equations Rabinowitsch trick Racah polynomials Racah W coefficient Racetrack (game) Racks and quandles Radar chart Rademacher complexity… …   Wikipedia

  • List of numerical analysis topics — This is a list of numerical analysis topics, by Wikipedia page. Contents 1 General 2 Error 3 Elementary and special functions 4 Numerical linear algebra …   Wikipedia

  • Renormalization — Quantum field theory (Feynman diagram) …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”