AltIMU-10 v4 sensor programming with arduino

Hi i am working with the altIMU board to display attitude and heading information similar to that of an attitude indicator. I merged the 3 sensor program codes which i obtained from a forum to display the data on the arduino serial monitor. The program which i am using to display the pitch and roll (attitude) data starts to display nan after a short while when the program is run and i have no idea why. Any help would be great guys. Ill attach the links to where i code the various codes as well as codes.

Vector.ino (1.84 KB)

sketch_dec05b.ino (7.24 KB)

Output.ino (2.71 KB)

matrix.ino (1.55 KB)

I2C.ino (2.72 KB)

DCM.ino (6 KB)

Compass.ino (1.97 KB)

The usual approach is to print out the values of some variables, in order to figure out where the NaN is coming from.