# Gravity–2-dimensional.LACE

# The small mass m moves within the gravitational potential of a mass M.
# The situation is analysed in polar coordinates.

# r'' = r * phi'^2 - gamma*M/r^2
# phi'' = -2* r' / r * phi'

include CompoundFunctions.LACE   # idivide

coefficient(1): +1 -> r0' # -1 to move initially towards M, +1 to  move away from it
coefficient(2): -1 -> -r0 # initial distance of m to M
coefficient(3): +1 -> phi0' 
coefficient(4): -1 -> -phi0 
coefficient(5): +1 -> gamma*M

iintegrate r*phi'^2, -gamma*M/r^2 -> -r' # input is r''
   IC: r0'
iintegrate -r' -> r
  IC: -r0

iintegrate -r'/r*phi', -r'/r*phi' -> -phi' # input is phi''
  IC: phi0'
iintegrate -phi' -> phi
  IC: -phi0
  
multiply r, -phi' -> -r*phi'
multiply -r*phi', -phi' -> r*phi'^2
multiply r, r -> r^2
idivide gamma*M, r^2 -> -gamma*M/r^2

idivide -r', -r*phi' -> r'/r*phi'
invert r'/r*phi' -> -r'/r*phi'
  
output(x): r      # distance
output(y): phi    # angle