fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. const int number_of_steps = 211;
  5. float dt = 0.5;
  6. float mass = 5900.0;
  7. // The r and theta variable sets
  8. float r[number_of_steps];
  9. float r_vel[number_of_steps];
  10. float r_acc[number_of_steps];
  11. float theta[number_of_steps];
  12. float theta_vel[number_of_steps];
  13. float theta_acc[number_of_steps];
  14. // Computations for Lift and Drag forces
  15. float Lift[number_of_steps];
  16. float Drag[number_of_steps];
  17. float vel_twind[number_of_steps];
  18. float sq_V[number_of_steps];
  19. float dy_pressure[number_of_steps];
  20. float density_rho[number_of_steps];
  21. // The sets of angles, and time
  22. float angle_of_attack[number_of_steps];
  23. float flight_path_angle[number_of_steps];
  24. float time[number_of_steps];
  25.  
  26. void Calc_Function(int i);
  27. void Save_Result();
  28.  
  29. int main() {
  30. // Set the initial conditions
  31. flight_path_angle[0] = -0.10471975333;
  32. r[0] = 122.0;
  33. r_vel[0] = 11.0*sin(flight_path_angle[0]);
  34. theta[0] = 0.0;
  35. theta_vel[0] = 11.0*cos(flight_path_angle[0])/r[0];
  36. time[0] = 0.0;
  37.  
  38. for(int i = 1; i < number_of_steps; i++) {
  39. // Calculate the new using the old value
  40. Calc_Function(i-1);
  41.  
  42. r_vel[i] = r_vel[i-1] + dt*r_acc[i-1];
  43. r[i] = r[i-1] + dt*r_vel[i-1];
  44.  
  45. theta_vel[i] = theta_vel[i-1] + dt*theta_acc[i-1];
  46. theta[i] = theta[i-1] + dt*theta_vel[i-1];
  47.  
  48. flight_path_angle[i] = atan2(r_vel[i-1], r[i-1]*theta_vel[i-1]);
  49. time[i] = time[i-1] + dt;
  50. }
  51. Calc_Function(number_of_steps-1); // Last accleration update
  52. Save_Result();
  53. printf("Done~~~~~\n");
  54. getchar();
  55. }
  56.  
  57. void Calc_Function(int i) {
  58. // The calculation of Lift and Drag forces
  59. density_rho[i] = 1.752*pow(10.0,9.0)*exp((6378.0-r[i])/6700.0);
  60. vel_twind[i] = r[i]*theta_vel[i] - 7.292*pow(10.0, -5.0)*r[i];
  61. sq_V[i] = r_vel[i]*r_vel[i] + vel_twind[i]*vel_twind[i];
  62. dy_pressure[i] = 0.5*density_rho[i]*sq_V[i];
  63. angle_of_attack[i] = atan2(r_vel[i], vel_twind[i]);
  64. Lift[i] = 0.4*(12.0*pow(10.0, -6.0))*dy_pressure[i];
  65. Drag[i] = 1.2*(12.0*pow(10.0, -6.0))*dy_pressure[i];
  66. // The calculation of accerlations
  67. r_acc[i] = -3.986*pow(10.0, 5.0)/(r[i]*r[i]) - (Drag[i]/mass)*sin(angle_of_attack[i]) + (Lift[i]/mass)*cos(angle_of_attack[i]) + r[i]*theta_vel[i]*theta_vel[i];
  68. theta_acc[i] = -(Drag[i]/mass)*cos(angle_of_attack[i])/r[i] - (Lift[i]/mass)*sin(angle_of_attack[i])/r[i] - 2*r_vel[i]*theta_vel[i]/r[i];
  69. }
  70.  
  71. void Save_Result() {
  72. FILE *pFile;
  73. pFile = fopen("Results.txt", "w");
  74. for (int i = 0; i < number_of_steps; i++) {
  75. fprintf(pFile, "%f\t %f\t %f\t %f\t %f\t %f\t %f\n", time[i], r[i], r_vel[i], r_acc[i], theta[i], theta_vel[i], theta_acc[i]);
  76. }
  77. fclose(pFile);
  78. }
  79.  
Runtime error #stdin #stdout 0s 2992KB
stdin
Standard input is empty
stdout
Standard output is empty