Thats a good example for using desciptive names for variables and defines.
Line 2:
M is defined as an integer, but not inizialized.Code:int i, j, k,m,n,M;
Line 8+9:
v and d are defined as double vectors with a size of M, but M isn't initialized.Code:double v[M*M]; double d[M];
Nobody knows how big or small this vectors are.
Line 104+105:
M is now a define to represent 3.Code:#define M 3 double Gyration[M*M] = { …
And Gyration is a double vector in size of 9.
But have v and d the right size?
To fix this, set line 104 as the first line (in front of the function).
Delete the integer M on line 2.
To avoid confusion, rename M to SIZE_M. It makes it clear that this is a defined name.