Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // método de euler para EDOs:
- // f(x+dx) = f(x) + dxF(f,x) (+ condição inicial)
- // EDO Colisão unidimensional
- #include <stdio.h>
- #define dt 0.00001
- #define v01 30
- #define v02 10
- #define m1 5
- #define m2 8
- int main(void)
- {
- int i;
- double v1,v2,t,x1,x2;
- x1=-10;
- x2=5;
- for (i=0;i<2e5;i++)
- {
- v1=v01;
- v2=v02;
- t=++i*dt;
- x1+=v1*dt;
- x2+=v2*dt;
- if (x1==x2 || (x1-x2)<=1)
- {
- v1=((m1-m2)/(m1+m2))*v01+ ((2*m2)/(m1+m2))*v02;
- v2=((2*m1)/(m1+m2))*v01-((m1-m2)/(m1+m2))*v02;
- }
- printf("%lf\t %lf\t %lf\t %lf\t %lf\n",t,x1,x2,v1,v2);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement