分子动力学理论篇(1)——牛顿力学、哈密顿动力学和相空间
程序员文章站
2024-01-18 22:23:16
...
分子动力学理论-总结
接下来我们画出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("--------------------------");
上一篇: 【Java并发编程】并发模拟的四种方式