An inverse finite element method for beam shape sensing: theoretical framework and experimental validation