Unified Approach to Electromagnetic Shape Inverse and Mechanical Coupled Problems via a Lagrangian Technique