Trajectory of moving objects(I)

时间:2019-10-25
本文章向大家介绍Trajectory of moving objects(I),主要包括Trajectory of moving objects(I)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Given the forces of objects and initial displacement/velocity, we can determine the trajectory as a function of time by the iteration. Here we focus on the case of one-dimension, considering the effect of friction force and many particle interactions.

(1) the effect of friction force

When the friction force is given above, the code shoulbe modified at the updating of velocity.

 Without friction, the velocity will increase as the time gradually, while there is a limit when the friction is considered.

(2) spring oscillator 

 For the ideal spring oscillator, we can obtain the equation when the friction of ground is neglected. Suppose the elastic coefficient k=1 and the initial displacement s(t=0)=0.1.

clear
k=1;s(1)=0.1;v(1)=0;
t(1)=0;dt=0.1;
for i=1:1000
  v(i+1)=v(i)-k*s(i)*dt;
  s(i+1)=s(i)+v(i+1)*dt;
  t(i+1)=t(i)+dt;
endfor

After the iteration, we can plot the displacement or velocity as a function of time.  

(3) case of two objects

 When there are two objects, we can write down the equations respectively. Suppose the free length of string is L=1, the force can be calculated according to the difference between L and the distance of object 1,2.

clear
k=1;s1(1)=0;v1(1)=1;
s2(1)=-1;v2(1)=0;
t(1)=0;dt=0.1;
for i=1:100
  v1(i+1)=v1(i)-k*(s1(i)-s2(i)-1)*dt;
  v2(i+1)=v2(i)+k*(s1(i)-s2(i)-1)*dt;
  s1(i+1)=s1(i)+v1(i+1)*dt;
  s2(i+1)=s2(i)+v2(i+1)*dt;
  t(i+1)=t(i)+dt;
endfor

After the iteration, we can obtain the displacement of 1 and 2 as a function of time (shown on the left). The figure on the right is the distance of 1 and 2, which shows a typical trajectory of single spring oscillator.

plot(t,s1,'o-')
hold on
plot(t,s2,'ro-')
xlabel('time')
ylabel('displacement')
figure
plot(t,s1-s2,'o-')

  

原文地址:https://www.cnblogs.com/xbyang99/p/11733176.html