Simulation of electromagnetic systems by coupling of magnetic and electric equations