Post Reply 
(50G) (49G+) Trapezoidal rule integration in RPL
11-17-2015, 11:55 AM (This post was last modified: 06-15-2017 01:57 PM by Gene.)
Post: #1
(50G) (49G+) Trapezoidal rule integration in RPL
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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(50G) (49G+) Trapezoidal rule integration in RPL - Marcio - 11-17-2015 11:55 AM



User(s) browsing this thread: 1 Guest(s)