Electron beam optics (particle betatron motion) and trajectory (centroid secular motion) in the FERMI@Elettra free electron laser (FEL) are modeled and experimentally controlled by means of the ELEGANT particle tracking code. This powerful tool, well known to the accelerator community, is here for the first time fully integrated into the Tango-server based high level software of an FEL facility, thus ensuring optimal charge transport efficiency and superposition of the beam Twiss parameters to the design optics. The software environment, the experimental results collected during the commissioning of FERMI@Elettra, and the comparison with the model are described. As a result, a matching of the beam optics to the design values is accomplished and quantified in terms of the betatron mismatch parameter with relative accuracy down to the 10 À3 level. The beam optics control allows accurate energy spread measurements with sub-keV accuracy in dedicated dispersive lines. Trajectory correction and feedback is achieved to a 5 m level with the implementation of theoretical response matrices. In place of the empirical ones, they speed up the process of trajectory control when the machine optics is changed, avoid particle losses that may occur during the on-line computation of experimental matrices, and confirm a good agreement of the experimental magnetic lattice with the model.