X-ray analysis of internal stresses in crystals I. general equations