Astronomical Algorithms

[WIP]

People who write their own computer programs often wonder why the machine gives inaccurate planet positions, an unreal eclipse track, or a faulty Moon phase. Sometimes they insist, bewildered, "and I used double precision, too." Even commercial software is sometimes afflicted with gremlins, which comes as quite a shock to anyone caught up in the mystique and presumed infallibility of computers. Good techniques can help us avoid erroneous results from a flawed program or a simplistic procedure--and that's what this book is all about.

1. Hints and Tips

RA α\alpha(Right Ascension) to degrees conversion: 1h = 15 degrees

---

Avoid powers in calculations using Horner's method. Suppose that one wants to calculate the value of the polynomial

y=A+Bx+Cx2+Dx3+Ex4y = A + Bx + Cx^2 + Dx^3 + Ex^4

It is better to write it as

y=A+x(B+x(C+x(D+E)))y = A + x(B + x(C + x(D + E)))

so that all power functions have disappeared and we only perform additions and multiplications. This is especially well suited for automatic calculation because powers are avoided.

---

Interesting way to exchange two variables X and Y (equivalent to X, Y = Y, X in Python):

X = X + Y
Y = X - Y
X = X - Y

3. Interpolation

Last updated

Was this helpful?