Small RPN exponential routine

01212015, 02:36 AM
Post: #12




RE: Small RPN exponential routine
(01202015 07:57 PM)James Dunn Wrote: Gerson, Is your exponential routine similar to Toth's? 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_{n1}\) (lines 019021). 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 

« Next Oldest  Next Newest »

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