MATLAB: Tracking the direction of a spacecraft - loss of precision

47 Views Asked by At

Imagine you have a target direction that we call " dir " , a unitary vector centred in Earth. Now, you have the trajectory of the spacecraft that is travelling to the boundary of the solar system, and each position is given in a heliocentric frame ( see image). You just want to know if the spacecraft is keeping the target direction " dir ". Imagine that nothing is moving except the spacecraft. Then, for each heliocentric position you do the following thing:

r_A = r-r_Earth

Where r_A is the geocentric position vector just for the first point, then you should do it for each point. So you compute the direction of r_A and you compare it with "dir".

Important: we imagine no forces are acting on the s/c, so the trajectory is straight.

It seems easy, but when the s/c go far and far away from the Sun, r becomes bigger and bigger, and the operation " r-r_Earth" can bring to loss of significance errors. Imagine that we quantify the errors between the actual direction and the target direction as angles between them, these angles start from 0 and then they reach values of 10^-4. This shouldn't happen since the trajectory is straight, no deviation should be observed. If you need, I can send you a small code of this problem. Thank you very much for your help guys. [Here the image](https://i.stack.imgur.com/jfiuJ.jpg)

I expect to have always a 0 error in direction.

1

There are 1 best solutions below

0
JanS On

If I understand correctly, you're losing precision because of round-off errors due to the values of r becoming bigger. My guess would be on round-off errors due to the limited digits of precision Matlab uses for it's doubles.

One option to avoid round-off errors is to switch to symbolic calculations using Matlab's Symbolic Math Toolbox, see this article on increasing precision and this one covering round-off errors.

Another idea would be to change the units of r, e.g. to AU or something custom. But I guess this depends on the level of precision you need.