Optimization and Inverse Problems in Electromagnetism