## `student::riemann` -- numerical approximation to an integral using rectangles

#### Introduction

`student::riemann``(f, x=a..b, n)` computes a numerical approximation to the integral int(f(x),x=a..b) using rectangles.

#### Call(s)

`student::riemann(f, x=a..b <, n>)`
`student::riemann(f, x=a..b <, n>, method)`

#### Parameters

`f` | - | arithmetical expression or a function in `x`
`x` | - | identifier
`a, b` | - | arithmetical expressions
`n` | - | a positive integer (number of rectangles)
`method` | - | one of the options Left, Middle, or Right

#### Options

`Left` | - | The height of each rectangle is determined by the value of the function at the leftpoint of each interval.
`Middle` | - | The height of each rectangle is determined by the value of the function at the middlepoint of each interval (the default method).
`Right` | - | The height of each rectangle is determined by the value of the function at the rightpoint of each interval.

#### Returns

an arithmetical expression.

#### Related Functions

`freeze`, `int`, `numeric::int`, `numeric::quadrature`, `student::plotRiemann`, `student::simpson`, `student::trapezoid`

#### Details

- `student::riemann``(f, x=a..b, n)` computes a numerical approximation to the integral int(f(x),x=a..b) using n rectangles.

  The height of each rectangle is determined by the value of the function at the middlepoint of each interval (as with option Middle).

- With `student::riemann``(f, x=a..b, n, Left)`, the height of each rectangle is determined by the value of the function at the leftpoint of each interval.

  Use option Right, if the rightpoint of each interval should be taken.

- `n` is the number of rectangles to use. The default value is 4.
- The result of `student::riemann` is an arithmetical expression which consists of frozen subexpressions of type `"sum"`.

  Use `unfreeze` to force the evaluation of the result.

#### Example 1

The numerical approximation to the integral int(e^x,x=-1..1) using 10 rectangles is:

    >> student::riemann(exp(x), x = -1..1, 10)

                           /    / i1        \            \
                        sum| exp| -- - 9/10 |, i1 = 0..9 |
                           \    \ 5         /            /
                        ----------------------------------
                                        5

The function values were taken at the middlepoint of each interval, the same as with option Middle.

We got an unevaluated expression, the formula for the corresponding approximation. Use `unfreeze` to force the evaluation of the result:

    >> unfreeze(%)

          exp(-1/2)   exp(1/2)   exp(-1/10)   exp(1/10)   exp(-3/10)
          --------- + -------- + ---------- + --------- + ---------- +
              5          5           5            5           5

             exp(3/10)   exp(-7/10)   exp(7/10)   exp(-9/10)   exp(9/10)
             --------- + ---------- + --------- + ---------- + ---------
                 5           5            5           5            5

Let us compute a floating-point approximation of the result:

    >> float(%)

                                    2.346489615

and compare the result with the approximation using the left- and rightpoint of each interval for the determination of the heights of the rectangles:

    >> float(student::riemann(exp(x), x = -1..1, 10, Left)),
       float(student::riemann(exp(x), x = -1..1, 10, Right));

                             2.123191605, 2.593272083

Finally, we compute the exact value of the definite integral int(e^x,x=-1..1):

    >> F:= int(exp(x), x = -1..1); float(F)

                                 exp(1) - exp(-1)

                                    2.350402387

#### Example 2

The general formula of an approximation of int(f(x),x=a..b) using 4 rectangles:

    >> F:= student::riemann(f(x), x = a..b)

             / b   a \    /  /                / b   a \ \            \
             | - - - | sum| f| a + (i4 + 1/2) | - - - | |, i4 = 0..3 |
             \ 4   4 /    \  \                \ 4   4 / /            /

To expand the frozen sum, enter:

    >> F:= unfreeze(F)

          / b   a \ /  / a   7 b \    / 3 a   5 b \    / 5 a   3 b \
          | - - - | | f| - + --- | + f| --- + --- | + f| --- + --- | +
          \ 4   4 / \  \ 8    8  /    \  8     8  /    \  8     8  /

              / 7 a   b \ \
             f| --- + - | |
              \  8    8 / /

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000