PermanentMagnetSim:

Path: SC/MagneticControl

% Simulate the attitude of a rigid spacecraft with permanent magnet in LEO
 Demonstrates how the magnet dipole aligns with the Earth magnetic field
 over time. Depending on the orbit inclination and altitude, the field
 strength and direction undergoes a periodic change throughout the
 orbit. The magnetic field varies at twice orbit rate as shown in the
 plot.
   
 The resulting motion is an undamped oscillation. The natural frequency
 of the oscillation changes with the square root of the inertia. The
 simulation includes gravity gradient torque as well.

 See also QLVLH, InertiaCubeSat, PermanentMagnetRHS, El2RV, OrbRate, Period,
 PltOrbit, RVFromKepler, BDipole, Constant, AnimateCube, Plot2D, Mat2Q, Q2Mat,
 Date2JD, Mat2Eul, Dot, Unit