Advertisement
Guest User

Untitled

a guest
Sep 25th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4. double Mm = 0.02897; //kg/mol molar mass of air
  5. double G  = 6.67300e-11; /* %in SI */
  6. double R  = 8.31; /* %gas constant */
  7. double rho_e = 5515; /* %kg/m^3, density of Earth */
  8. double rho_h = 1400; /* %kg/m^3, density of human body */
  9. double R0    = 6371e3; /* %m, mean Earth radius */
  10.  
  11. double Cd    = 1.3; /* %drag coeff. of human body */
  12. double A     = 0.7; /* %m^2, incident suface area of human body */
  13. double T     = 300; /* %K, temperature */
  14. double p0    = 1e5; //Pa, 1 atmosphere
  15. double m     = 80;  //kg, human weight
  16.  
  17. const double pi = 3.14159;
  18.  
  19. double f1(double x1, double x2)
  20. {
  21.   return x2;
  22. }
  23.  
  24. double f2(double x1, double x2)
  25. {
  26.   return (-4/3*pi*G*rho_e*x1 + Cd*A/2/m*Mm/R/T*(p0 + 2/3*G*rho_e*pi*(R0*R0 - x1*x1))*x2*x2);
  27. }
  28.  
  29. int main()
  30. {
  31.   double dt = 0.5; /* seconds */
  32.  
  33.   /* initial conditions */
  34.   double x1 = R0;
  35.   double x2 = 0;
  36.   double t  = 0;
  37.   while (x1 > 0)
  38.     {
  39.       double x1dot = f1(x1, x2);
  40.       double x2dot = f2(x1, x2);
  41.  
  42.       double hstep1 = x1 + x1dot*dt/2;
  43.       double hstep2 = x2 + x2dot*dt/2;
  44.      
  45.       printf("%f\t%f\t%f\n", t, x1, x2);
  46.  
  47.       x1 += f1(hstep1, hstep2)*dt;
  48.       x2 += f2(hstep1, hstep2)*dt;
  49.       t  += dt;
  50.     }
  51.  
  52.   return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement