Advertisement
luizaspan

EDO Partícula livre 1D

May 12th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. // método de euler para EDOs:
  2. // f(x+dx) = f(x) + dxF(f,x) (+ condição inicial)
  3.  
  4. // particula livre 1D
  5. // colisão elástica (v=-v) na parede em x=5;
  6.  
  7. #define x0 0
  8. #define v0 1
  9. #define dt 0.01
  10.  
  11. #include <stdio.h>
  12.  
  13. int main(void)
  14. {
  15.   int i=0;
  16.   double x,v,t;
  17.  
  18.   // v(t+dt)=v(t) cte
  19.   // x(t+dt)=x(t)+dt*v(t)
  20.  
  21.   v=v0;
  22.  
  23.   for (i=0;i<10000;i++)
  24.     {
  25.       t=++i*dt;
  26.       x=x+dt*v;
  27.  
  28.       if (x>=5)
  29.     {
  30.       v=-v;
  31.     }
  32.  
  33.       printf("%lf %lf\n",x,t);
  34.     }
  35.      
  36.   return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement