Numerical representation

Terry Reedy tjreedy at udel.edu
Mon Mar 7 16:35:19 EST 2011


On 3/7/2011 1:59 PM, Jon Herman wrote:
> And for the sake of completeness, the derivative function I am calling
> from my integrator (this is the 3 body problem in astrodynamics):
>
> def F(mu, X, ti):
>
>      r1= pow((pow(X[0]+mu,2)+pow(X[1],2)+pow(X[2],2)),0.5)

     x0 = X[0]; x1 = X[1]; x2 = X[2]
     r1 = sqrt((x0+mu)**2) + x1*x1 + x2*x2)
     etc...
might be faster. Certainly, repeated lookups of pow is slow
and above is easier to read.

>      r2= pow((pow(X[0]+mu-1,2)+pow(X[1],2)+pow(X[2],2)),0.5)
>
>      Ax= X[0]+2*X[4]-(1-mu)*(X[0]+mu)/r1**3-mu*(X[0]-(1-mu))/r2**3
>      Ay= X[1]-2*X[3]-(1-mu)*X[1]/r1**3-mu*X[1]/r2**3
>      Az= -(1-mu)*X[2]/r1**3-mu*X[2]/r2**3
>
>      XDelta=array([X[3], X[4], X[5], Ax, Ay, Az])
>
>      return XDelta
>\


-- 
Terry Jan Reedy




More information about the Python-list mailing list