Mathematical imaging using electric or magnetic nanoparticles as contrast agents