! Exact solution of 2-Body Problem:
! x = cos(u)-e
! y = sqrt(1-e**2)*sin(u)
! x'=-sin(u)/(1-e*cos(u))
! y'= sqrt(1=e**2)*cos(u)/(1-e*cos(u))
! "u" is given by: u-e*sin(u) =t
!
subroutine exact(t, xExact)
use work
implicit real(8) (a-h, o-z)
real(8) xExact(4)

! Solve for "u" - by iteration:
!Define u =g(u):
g(u, e, t) =e*sin(u) +t

eps =1D-13
nlim =1000

u0 =0.
iter =0
do while (iter <=nlim)
iter =iter +1
u1 =g(u0,e,t)
dif =u1 -u0
	if(dabs(dif) <=eps) then
!	write(1,'(/, a, I3, 3x, a, 1pD10.3, a)')  '(iter:', iter,'dif=', dif,')'
	exit
	else
	u0 =u1
	endif
end do

u =u1
! Compute the solution
ee =dsqrt(1-e**2)
xExact(1) = cos(u)-e			!x
xExact(2) = ee*sin(u)			!y
xExact(3)=-sin(u)/(1-e*cos(u))	!x'
xExact(4) = ee*cos(u)/(1-e*cos(u))	!y'

end subroutine exact
