分子动力学理论篇(1)——牛顿力学、哈密顿动力学和相空间

分子动力学理论-总结

在这里插入图片描述

接下来我们画出harmonic spring 在相空间的轨迹:在这里插入图片描述
MALAB 代码如下:

clc;clear;
%--------------------------------%
% initial setting 
step = 0.1;
X_initial  = -4;
V_initial = 0;
lambda    = 1;
mass      = 1;
X_current = X_initial;
V_current = V_initial;
t         = 0;run = 0;
%--------------------------------%
% Run
while (t<=100)
  t   = t+step;
  half_t    = 0.5*step;
  a = -X_current;
  V_current = V_current+a*step;
  X_current = X_current+V_current*step;
  momentum  = V_current;
 %---------------------------------------%
 % plot 
  hold on;  
  s = scatter(X_current,momentum);
  s.LineWidth = 0.6;
  s.MarkerEdgeColor = 'b';
  s.MarkerFaceColor = [0 0.5 0.5];
  run = run +1;  
 %---------------------------------------%
 % output 
  if(mod(run,100)==0)
      fprintf("The step %d is finished!\n",run);      
  end 
end
disp("--------------------------");
disp("--------ALL DONE!!!-------");
disp("--------------------------");

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43689832/article/details/108942860

相关文章