Here, we present some simple examples, which describe how to run MagneticFriction and how to use the data generated by the simulations. If some steps are unclear, please check README. All .m files for the examples can be found in the Folder example. The presented examples here also act as a demo for MagneticFriction. They also provide the tools to reproduce most of the data depicted in [1].
1) Performing your first simulations with MagneticFriction
As an example for the execution of the simulations, the following steps describe how to run numerical calculations for three distinct slider-substrate separations (6.5mm, 8.5mm, and 11.0mm). First, download all .m files corresponding to MagneticFriction from this repository into a single folder. Then, open MagneticArray.m with Matlab. Go to line 82 and adjust the variable scan_value so that the line reads:
scan_value = [0.0065, 0.0085, 0.011];
Here, scan_value represents the three separations for which the calculations are performed. The simulation can be started by executing MagneticArray.m in MATLAB.
If the simulations are successful, three .mat files can be found in the folder that contains MagneticArray.m (height0.0065.mat, height0.0085.mat, and height0.011.mat). These files contain the output data and can be utilized for further analysis. The simulation program is expected to run roughly 900 seconds per separation on an AMD Ryzen 7 PRO 7730U.
2) Calculate the average magnetic friction
Copy the file Example_Avg_Force.m (see example folder) into the folder that contains the .mat files obtained from the simulations. Run the example script with MATLAB. If the calculations are successful, the MATLAB console gives the average magnetic frictions corresponding to the .mat files. For instance, if the slider-substrate separations 6.5mm, 8.5mm, and 11.0mm of the other examples are used, the results should be roughly -0.21N, -1.33N, and -0.0045N, respectively.
3) Calculate the average total friction
Copy the file Example_Total_Force.m (see example folder) into the folder that contains the .mat files obtained from the simulations. Run the example script with MATLAB. If the calculations are successful, the MATLAB console gives the average frictions (magnetic and mechanical contributions) corresponding to the .mat files. For instance, if the slider-substrate separations 6.5mm, 8.5mm, and 11.0mm of the other examples are used, the results should be roughly -1.73N, -1.99N, and -0.36N, respectively.
4) Plot force over time
Copy the file Example_Force_Over_Time.m (see example folder) into the folder with the .mat files and execute the MATLAB script. If the same slider-substrate separations as in the other examples are used, three plots should pop up, each showing the x-component of the total interaction force between the slider and the substrate. The x-axis measures time in seconds, and the y-axis corresponds to force in Newtons.
5) Calculate the average order parameter
Copy the file Example_Order_Parameter.m (see example folder) into the folder with the simulation results. Run the MATLAB script. If everything works, the MATLAB console gives the average order parameter corresponding to the different .mat files. If the slider-substrate separations 6.5mm, 8.5mm, and 11.0mm of the other examples are used, the results should be roughly 1.00, 0.67, -0.97, respectively.
6) Plot orientation over time
Copy the file Example_Angle_Over_Time.m (see example folder) into the folder with the .mat files and execute the example MATLAB script. If the same slider-substrate separations as in the other examples are used, three plots should pop up. Each of these plots shows the orientation angle of the magnetic moment in the middle of the slider. On the x-axis, the time is given in seconds. On the y-axis, the angles are depicted. Note that the angle is always folded back to the interval [0,2
[1] Gu, H., Lüders, A. & Bechinger, C. Non-monotonic magnetic friction from collective rotor dynamics. Nat. Mater. (2026). https://doi.org/10.1038/s41563-026-02538-1