Small RPN exponential routine
01-21-2015, 02:36 AM
Post: #12
 Thomas Klemm Senior Member Posts: 1,447 Joined: Dec 2013
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
 « Next Oldest | Next Newest »

 Messages In This Thread Small RPN exponential routine - Gerson W. Barbosa - 01-02-2015, 10:25 PM RE: Small RPN exponential routine - Thomas Klemm - 01-03-2015, 08:42 AM RE: Small RPN exponential routine - Gerson W. Barbosa - 01-03-2015, 10:53 AM RE: Small RPN exponential routine - Gerson W. Barbosa - 01-03-2015, 05:31 PM RE: Small RPN exponential routine - Thomas Klemm - 01-03-2015, 08:33 PM RE: Small RPN exponential routine - Gerson W. Barbosa - 01-04-2015, 01:14 AM RE: Small RPN exponential routine - James Dunn - 01-20-2015, 07:57 PM RE: Small RPN exponential routine - Gerson W. Barbosa - 01-20-2015, 11:48 PM RE: Small RPN exponential routine - Namir - 01-21-2015, 12:34 AM RE: Small RPN exponential routine - Gerson W. Barbosa - 01-21-2015, 12:46 AM RE: Small RPN exponential routine - Namir - 01-20-2015, 09:24 PM RE: Small RPN exponential routine - Gerson W. Barbosa - 01-21-2015, 04:03 AM RE: Small RPN exponential routine - Thomas Klemm - 01-21-2015 02:36 AM RE: Small RPN exponential routine - Thomas Klemm - 01-21-2015, 03:18 AM RE: Small RPN exponential routine - Gerson W. Barbosa - 01-21-2015, 03:48 AM RE: Small RPN exponential routine - Namir - 01-22-2015, 08:41 AM RE: Small RPN exponential routine - Gerson W. Barbosa - 01-22-2015, 06:59 PM RE: Small RPN exponential routine - Namir - 01-23-2015, 05:11 PM RE: Small RPN exponential routine - Gerson W. Barbosa - 01-23-2015, 06:48 PM RE: Small RPN exponential routine - Eddie W. Shore - 01-27-2015, 12:56 PM RE: Small RPN exponential routine - Thomas Klemm - 01-27-2015, 08:52 PM RE: Small RPN exponential routine - Albert Chan - 01-30-2019, 07:21 PM

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