Magnetic field analysis in hysteretic materials by minimization of constitutive error