Advertisement
luizaspan

Colisão unidimensional /não acabado nem testado II

May 14th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // método de euler para EDOs:
  2. // f(x+dx) = f(x) + dxF(f,x) (+ condição inicial)
  3.  
  4. // EDO Colisão unidimensional
  5.  
  6. #include <stdio.h>
  7.  
  8. #define dt 0.00001
  9. #define v01 30
  10. #define v02 10
  11. #define m1 5
  12. #define m2 8
  13.  
  14. int main(void)
  15. {
  16.   int i;
  17.   double v1,v2,t,x1,x2;
  18.  
  19.   x1=-10;
  20.   x2=5;
  21.  
  22.   for (i=0;i<2e5;i++)
  23.     {
  24.       v1=v01;
  25.       v2=v02;
  26.  
  27.       t=++i*dt;
  28.  
  29.       x1+=v1*dt;
  30.       x2+=v2*dt;
  31.  
  32.       if (x1==x2 || (x1-x2)<=1)
  33.     {
  34.       v1=((m1-m2)/(m1+m2))*v01+ ((2*m2)/(m1+m2))*v02;
  35.       v2=((2*m1)/(m1+m2))*v01-((m1-m2)/(m1+m2))*v02;
  36.     }
  37.       printf("%lf\t %lf\t %lf\t %lf\t %lf\n",t,x1,x2,v1,v2);
  38.     }
  39.  
  40.   return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement