An efficient and robust fiber optic alignment method for locating the optimal coupling position is critical to fiber optic packaging automation, and thus to photonics manufacturing. The often used hill-climbing type alignment method is gradient-based, 1-D "blind" searching, which is difficult for dealing with angular misalignments and the alignment of fiber arrays. This work presents a novel alignment method consisting of the Hamiltonian algorithm and Matlab/Simulink software tools. The Hamiltonian algorithm utilizes the inherent dynamic properties of the system to guide the movement of the fiber tip, and the Matlab/Simulink provides an efficient tool for solving Hamiltonian equations as well as output feedback control. Simulation results are obtained for the active alignment of single-channel fiber optic devices and multichannel-arrayed fiber optic devices, respectively. Trajectories of the searching path are demonstrated to be smooth. It is shown that time for multidegree of freedom alignment is significantly reduced compared to the conventional hill-climbing type alignment method. It is also demonstrated that, for arrayed fiber optic devices, a balanced fiber optic coupling result for all fibers can be easily reached.