Magnetics simulation and theoretical analysis in matlab