11-17-2015, 11:55 AM

Hello,

I have been using this code for years now and due to its simplicity, it has never failed.

<< \(\rightarrow\) M

<< M SIZE OBJ\(\rightarrow\) DROP DROP 'p' STO 0 'A' STO

2 p FOR i 'M(i,1)' \(\rightarrow\)NUM 'M(i-1,1)' \(\rightarrow\)NUM - 'M(i,2)' \(\rightarrow\)NUM 'M(i-1,2)' \(\rightarrow\)NUM + x 'A' \(\rightarrow\)NUM + 'A' STO NEXT

'A' \(\rightarrow\)NUM 2 / "AREA" \(\rightarrow\)TAG >>

'A' 'p' PURGE PURGE

>>

Although not optimized and is actually FORTRAN translated into RPL, this code is fast calculating the area under a curve in accordance with the trapezoidal rule:

\[ \int_{x_1}^{x_n} y(x) dx \approx \frac{1}{2} \sum_{k=1}^{n-1} (x_{k+1}-x_{k})(y_{k+1}+y_{k}) \]

Marcio

I have been using this code for years now and due to its simplicity, it has never failed.

<< \(\rightarrow\) M

<< M SIZE OBJ\(\rightarrow\) DROP DROP 'p' STO 0 'A' STO

2 p FOR i 'M(i,1)' \(\rightarrow\)NUM 'M(i-1,1)' \(\rightarrow\)NUM - 'M(i,2)' \(\rightarrow\)NUM 'M(i-1,2)' \(\rightarrow\)NUM + x 'A' \(\rightarrow\)NUM + 'A' STO NEXT

'A' \(\rightarrow\)NUM 2 / "AREA" \(\rightarrow\)TAG >>

'A' 'p' PURGE PURGE

>>

Although not optimized and is actually FORTRAN translated into RPL, this code is fast calculating the area under a curve in accordance with the trapezoidal rule:

\[ \int_{x_1}^{x_n} y(x) dx \approx \frac{1}{2} \sum_{k=1}^{n-1} (x_{k+1}-x_{k})(y_{k+1}+y_{k}) \]

Marcio