Code for calculating NED X