Post Reply 
Small RPN exponential routine
01-21-2015, 02:36 AM
Post: #12
RE: Small RPN exponential routine
(01-20-2015 07:57 PM)James Dunn Wrote:  Gerson, Is your exponential routine similar to Toth's?
It works, but I wonder how. Could someone explain? Thanks.

Toth's program calculates the partial sums:

\(1\)
\(1+x\)
\(1+x+\frac{x^2}{2}\)
\(1+x+\frac{x^2}{2}+\frac{x^3}{6}\)
\(1+x+\frac{x^2}{2}+\frac{x^3}{6}+\frac{x^4}{24}\)
(...)

It returns if the value doesn't change anymore. This value is kept in register 9 while the original x is kept in register 8. The terms to be added are calculated recursively from the previous value: \(a_n=\frac{x}{n}a_{n-1}\) (lines 019-021). The index \(n\) is kept in register I.

Horner's method let us rewrite the expression:

\(1+x(1+\frac{x}{2}(1+\frac{x}{3}(1+\frac{x}{4}(...)))\)

My program calculates that inside out using classic RPN style. Thus the loop is inverted: the index is going down to 0. From a numerical point of view that's favorable as it reduces cancelation: the values that are added are of a similar size.

Best is to step through the program using special values like 2 that are easy to follow.

HTH
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Small RPN exponential routine - Namir - 01-21-2015, 12:34 AM
RE: Small RPN exponential routine - Namir - 01-20-2015, 09:24 PM
RE: Small RPN exponential routine - Thomas Klemm - 01-21-2015 02:36 AM
RE: Small RPN exponential routine - Namir - 01-22-2015, 08:41 AM
RE: Small RPN exponential routine - Namir - 01-23-2015, 05:11 PM



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