一个非常难的题目(自己编的,自己把自己给难住了)

4个回答

  • 这个问题在理论上不复杂,只是数据复杂,具体做要实际计算机模拟仿真.首先把弹性碰撞的方程列出来然后建立简谐运动的仿真:s(n+1)=vn*dtv(n+1)=-w^2s(n)dtw=sqrt(K/M)我做了初始K=1,M=1,V=1,时间间隔是0.001的仿真,如图;当4个物体每走一步,都要判断是否是谐运动,是否发生碰撞.然后我做了10000步,发现当440步左右,4个物体都开始脱离弹簧,而匀速直线运动了.详细见图吧,图表示了4个物体的位置随时间的变化using System;using System.Collections.Generic;using System.Text;using System.IO;namespace collision{class State{public double speed;public double position;public bool isTouched;public bool canTouch = false;public State(double s, double pos, bool t){speed = s; position = pos; isTouched = t;}}class Simulation{private State[] nodes = new State[4];private double dt;private double w;public Simulation(double delta, double K,double M, double V){dt = delta;w = Math.Sqrt(K / M);for (int i = 0; i < 4; i++){nodes[i] = new State(0, i * 0.002, false);if (i == 0){nodes[i].speed = -V;nodes[i].isTouched = false;nodes[i].canTouch = true;}}}public void Step(State s){if (!s.isTouched){s.position += s.speed * dt;if (s.canTouch s.position < 0 s.speed < 0){s.isTouched = true;} }else{double pos = s.position;s.position += s.speed * dt;s.speed += -w * w * pos;}if (s.position >= 0 s.speed >= 0)s.isTouched = false;}public void Collision(State s1, State s2){double v1 = s1.speed;double v2 = s2.speed;s1.speed = (4 * v2 - v1) / 3;s2.speed = (2 * v1 + v2) / 3;double pos = (s1.position + s2.position) / 2;s1.position = pos - 0.001;s2.position = pos + 0.002;}public void Run(long tick){StreamWriter write = new StreamWriter("test.txt");for (int i = 0; i < tick; i++){foreach (State s in nodes){Step(s);}for (int j = 0; j < 3; j++){if (IsTouched(nodes[j], nodes[j + 1])){Collision(nodes[j], nodes[j + 1]);}}string str = string.Format("{0}t{1}t{2}t{3}t",nodes[0].position, nodes[1].position, nodes[2].position, nodes[3].position);write.WriteLine(str);}write.Close();}public static bool IsTouched(State s1, State s2){return Math.Abs(s1.position - s2.position) < 0.001;}}class Program{static void Main(string[] args){Simulation s = new Simulation(0.001, 1, 1, 1);s.Run(10000);}}}