Taylor Series

Programs: RMsexp.z80, RMscos.z80, RMssin.z80

These are some more recent programs of mine, prompted by musings about using Taylor series on the Diehl programmable calculator to create trig. functions, which weren't provided with the machine. They are in a similar vein as the slow square root program and so naming and headers reflect this. They are very simple, but show the power of the method.

These 3 programs calculate e**x, cos(x) and sin(x) respectively. The latter two take input in degrees and convert it to radians. All show successive iterations as new terms in the series are added and stop when these become very small (e**x), or 0 (trig. programs).

A couple of comments - first, in the trig. programs, the series converge quite quickly, but less so for e**x , due to the nature of the terms in the series and that's why I don't wait for terms to be become 0 for the e**x program. Second, successive iterations seem to be repeated, as shown in the above example for cos(1). I think some rounding is going on internally within the Spectrum - new terms are non-zero, yet have no impact on the printed result. 

At the end of each run, the result as provided by the Spectrum's own functions is also given for comparison. Note the difference in the example above for cos(1). In fact, having compared the answer calculated by my program with that provided by calculators, my answer is more accurate than the Spectrum's!

However, I should also point out that in the example below - cos(90) - my code produces a tiny (negative) number which should really be rounded up to 0, which is the answer provided correctly by the Spectrum!