COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Riemann Sums in the HP 49G+

• Email
• Follow

```Good morning everyone,

I have a dilemma. I cant figure out how to do Riemann Sum's using the
HP 49G+. I have found several programs for the 48 Series, but I have
been unsuccessful on converting the code from 48 to 49.
Anyone has code for the 49 that works to do Riemann Sum's?

:( I should be ashamed of myself!

GS

```
 0
Reply gen.sicaeros (1) 3/16/2006 5:04:40 PM

See related articles to this posting

```Below are some Riemann Sum programs I put together for my own use.
I've got similar ones for Trapezoid Method, Simpson's Rule, and
Simpson's 3/8 Rule.

Basically, do what you would normally do to evaluate an integral, but
then enter the number of steps and indicate which Riemann you want (0
for left, 1 for middle, 2 for right) and then run the RIEMANN program.

For example, to estimate the integral from 1 to 3 of 1/X with respect
to X using 60 steps with midpoint evaluations, you would enter

1.   3.   '1/X'   'X'   60.   1.   RIEMANN

or if you're lazy like me, you can use the shortcut programs LRIEMX,
MRIEMX, RRIEMX which do left, mid, and right evaluation using the
default variable (typically X).

1.   3.   '1/X'   60.   LRIEMX

1.   3.   '1/X'   60.   MRIEMX

1.   3.   '1/X'   60.   RRIEMX

I've included stack diagram snippets from the documentation I've put
together.

Let me know if any of this is unclear.

It would be best to copy and paste the programs below to text files and
then transfer them to the calculator, but if you're typing them in by
hand, note that \GS is the summation Sigma character.

Enjoy,
Wes Loewer

=============================================================
RIEMANN (Riemann Sum)

[lower_limit   upper_limit   integrand   'var'   n   lmr   -->
'result']

example:
[ 1.   3.   '1/X'   'X'   60.   1.   -->   1.09857114528 ]

n = the number of iterations
lmr = indicates whether the sum is evaluated on the left, middle, or
right of the section.
(Left = 0, Middle = 1, Right = 2)
result = the approximate area under the curve

------------------------------
%%HP: T(3)A(D)F(.);
\<< \-> xleft xright fnc xvar steps lmr
\<< PUSH -105. SF xleft \->NUM 'xleft' STO xright \->NUM 'xright' STO
steps \->NUM IP 'steps' STO lmr \->NUM IP 'lmr' STO
IF lmr 0. < lmr 2. > OR
THEN 1. 'lmr' STO
END xright xleft - steps / \-> deltax
\<< 'n' 0. steps 1. - fnc xvar xleft lmr deltax * 2. / + 'n' deltax
* + 2. \->LIST | \GS deltax *
\>> POP
\>>
\>>

=============================================================

LRIEMX (Riemann Sum, Left edge evaluation, default variable)

[lower_limit   upper_limit   integrand   n   -->   'result']

example:
[ 1.   3.   '1/X'   60.   -->   1.10980569415]

n = the number of iterations
result = the approximate area under the curve

------------------------------
%%HP: T(3)A(D)F(.);
\<< RCLVX SWAP 0. RIEMANN
\>>

=============================================================

MRIEMX (Riemann Sum, Midpoint evaluation, default variable)

[lower_limit   upper_limit   integrand   n   -->   'result']

example:
[ 1.   3.   '1/X'   60.   -->   1.09857114528 ]

n = the number of iterations
result = the approximate area under the curve

------------------------------
%%HP: T(3)A(D)F(.);
\<< RCLVX SWAP 1. RIEMANN
\>>

=============================================================

RRIEMX (Riemann Sum, Right edge evaluation, default variable)

[lower_limit   upper_limit   integrand   n   -->   'result']

example:
[ 1.   3.   '1/X'   60.   -->   1.08758347193 ]

n = the number of iterations
result = the approximate area under the curve

------------------------------
%%HP: T(3)A(D)F(.);
\<< RCLVX SWAP 2. RIEMANN
\>>

=============================================================

```
 0

```> For example, to estimate the integral from 1 to 3 of 1/X with respect
> to X using 60 steps with midpoint evaluations, you would enter

But one advantage of a Riemann Sum is that the subintervals don't have to be
equal.  Do you have an algorithm that allows the user to enter the subinterval
points and selects a random point within them or do you just assume they're equal?

Tom Lake

```
 0

```> But one advantage of a Riemann Sum is that the subintervals don't have to be
> equal.  Do you have an algorithm that allows the user to enter the subinterval
> points and selects a random point within them or do you just assume they're equal?

Sorry, I don't have such an algorithm, but it doesn't seem too hard to
put in something that would select a random point within a subinterval.
I don't think it could be called a "Riemann Sum" any more, but would
be interesting.

Even better are algorithms that change the size of the subinterval, not
randomly, but in a deterministic manner so as to improve the accuracy
of the result.  I don't have one of these either.  I suspect that's
what the calculator uses for its built-in method.

Can anybody confirm what method the calculator uses?

-wes

```
 0

```Wes!
Thank you very much for your help, you rock!

```
 0

```On Thu, 16 Mar 2006 14:28:25 -0600, Wes wrote:

> Can anyone confirm what method the calculator uses?

Romberg (with samples unevenly spaced using a polynomial,
rather than simple halving, to sample more near the endpoints,
and in fact to avoid any evaluation at the endpoints
of the interval, where many integrable functions diverge).

The numeric solver and numerical integration algorithms
were first developed for the HP34C by Prof. W. Kahan,
whose articles in the "HP Journal" (circa 1980)
can be obtained on CD from
http://www.hpmuseum.org/cd/cddesc.htm

http://mathworld.wolfram.com/RombergIntegration.html
http://www.biostat.umn.edu/~john-c/5421/notes.031
http://www.cse.uiuc.edu/eot/modules/integration/romberg

Romberg integration for your Casio FX-7400G or CFX-9850G
http://www.brianhetrick.com/casio/gmrombrg.html

[r->] [OFF]
```
 0

```The Riemann sum , as I understand it, does not require any rule for choosing
the point that the summand is evaluated at within the subinterval. The only
requirement is for some rule for creating the partition. The rule could pick
some random subinterval lengths even. An integral is yet another matter.
"Wes" <wjltemp-gg@yahoo.com> wrote in message
>> But one advantage of a Riemann Sum is that the subintervals don't have to
>> be
>> equal.  Do you have an algorithm that allows the user to enter the
>> subinterval
>> points and selects a random point within them or do you just assume
>> they're equal?
>
> Sorry, I don't have such an algorithm, but it doesn't seem too hard to
> put in something that would select a random point within a subinterval.
> I don't think it could be called a "Riemann Sum" any more, but would
> be interesting.
>
> Even better are algorithms that change the size of the subinterval, not
> randomly, but in a deterministic manner so as to improve the accuracy
> of the result.  I don't have one of these either.  I suspect that's
> what the calculator uses for its built-in method.
>
> Can anybody confirm what method the calculator uses?
>
> -wes
>

```
 0

```>> Even better are algorithms that change the size of the subinterval, ...

> Romberg (with samples unevenly spaced using a polynomial, ...

Yes, thanks.  That's the one I was thinking of but couldn't remember
the name off the top of my head.

(banging head against desk) I use Maxima as my computer CAS and have
typed "romberg" a gajillion times.

Gauss-Kronrod is the other one I was trying to think of.

-wes

```
 0