## conversion from cartesian to fractional coordinates

Hi all,

I have been trying to write code to convert from cartesian to fractional coordinates. I think everything is correct in my code (i have used wikipedia as reference - http://en.wikipedia.org/wiki/Fractional_coordinates), but still, the code doesn't work for some test values. The code is here http://codepad.org/sOV5ws5R. The code has the test data in there, if you want to check.

Could there be something wrong with the orientation of the axes? In wikipedia it has been assumed that cartesian coordinate axes X is in line with the lattice vector 'a'. It might be that the data I have doesn't correspond to this scheme (that the lattice vector 'a' is taken along x-axis). How to check if this the data which I have adheres to this scheme or is some other axis is directional along x-axis?

Other references that might be helpful -
http://www.angelfire.com/linux/myp/FracCor/fraccor.html
http://cci.lbl.gov/cctbx/frac_cart.html

I have really tried hard to find a solution for this, but couldn't find out where I am going wrong.

 It seems like you're doing a lot more work than necessary. You want something like: $$\vec{R} = x_1 \vec{a}_1 + x_2 \vec{a}_2 + x_3 \vec{a}_3$$ which can be written in matrix form as $$\vec{R} = A \cdot \left( \begin{array}{c} x_1 \\ x_2 \\ x_3 \end{array}\right)$$ where the matrix A is formed with the vectors a_i as its columns. Then you just need to invert the matrix to find the x's.