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.01
- #define v01 10
- #define v02 -15
- #define m1 3
- #define m2 4
- int main(void)
- {
- int i;
- double t,x1,x2,v1,v2;
- x1=20;
- x2=35;
- for (i=0;i<=10000;i+=2)
- {
- t=++i*dt;
- x1+=v01*dt;
- x2+=v02*dt;
- v1=v01;
- v2=v02;
- if (x2==x1)
- {
- 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