Sensitivity analysis enables powerful gradient-based mathematical programming techniques in the optimization of electromechanical products with respect to electromagnetic compatibility requirements. We present a sensitivity analysis method based on finite element solutions of both a magnetoquasistatic system in a tree-cotree gauge and an electrostatic system. A repeated application of the adjoint method ensures a high computational efficiency, which is showcased in a comparison with an earlier approach. Application examples provided are the optimization of a noise filter and the sensitivity computation of a choke with dispersive magnetic core.