## To run this script, type 
##      planet0
##
## This simple planet demonstration
## simulates the motion of the planet and plots 
## it as it goes, WITHIN THE LOOP.
## Every equation has its dimensions shown. This script 
## has a fixed initial condition. See planet10 for a more 
## general approach.
##
## In planet0a, the "plot" command is used.
## In planet0,  the "gplot" command is used.
##    For this example, "gplot" works much faster, 
##    and the command is simpler too.

# Gravitational parameter of sun 
A = 238 ; #  [L^3 T^{-2}] 

################################################
# Duration of simulation, and time-step; and initial time 
T = 1000 ;  dt = 1 ; t = 0 ; 
# T and dt and t have dimensions [T]
################################################
# Initial condition for position and velocity
################################################
 x = [ 93 , 0 ] ;
# x has dimensions [L]
 v = [0,1.1] ;
# v has dimensions [L/T]
################################################

## prepare the plot
figure(1); axis([-100 100 -100 100]); gset pointsize 3 ; gset nokey ;
axis("equal");
sun = [ 0 0] ;

while( t < T ) 
     ## every loop, plot the state: 
     ## plot a yellow sun point "@" and a blue planet point "x"
     plot(sun(:,1),sun(:,2), "b@", x(:,1),x(:,2), "mx") ;
##     gplot sun with points 3 3, x with points 5 4               ##

     t = t + dt ;
 ##  [T] +=  [T] 
     x  = x + v * dt ;
 ##  [L] += [L/T] * [T] 
     
     v = v - A * x / (x*x')**(3.0/2.0) * dt ;
     ## [L/T] -= ( [L^3 T^{-2}] * L / L^3 )  			      

endwhile

