fork(1) download
  1. #include <stdio.h>
  2.  
  3. // stałe fizyczne
  4. const double ro = 1.25; // gestosc powietrza [kg/m^3]
  5. const double g = 9.81; // przyspieszenie ziemskie [m/s^2]
  6.  
  7. double Faero(double S, double C, double v) { return v*v*S*C*ro/2; }
  8.  
  9. int main(void) {
  10. // parametry eksperymentu stale w czasie
  11. double m1 = 0.2; // masa ciala 1 [kg]
  12. double m2 = 1.3; // masa ciala 2 [kg]
  13.  
  14. double Cx1 = 0.1; // wspolczynnik oporu ciala 1
  15. double Cx2 = 0.1;
  16.  
  17. double S_1 = 0.006; // pole poprzecznego przekroju [m^2]
  18. double S_2 = 0.006;
  19.  
  20. double dt = 0.1; // modelowy odcinek czasu [s]
  21. double Tmax = 10.0; // limit czasu [s]
  22.  
  23. // zmienne w czasie
  24. double a1 = 0.0; // przyspieszenie [m/s^2]
  25. double a2 = 0.0;
  26. double f1 = 0.0; // sila oporu [N]
  27. double f2 = 0.0;
  28. double v1 = 0.0; // predkosc [m/s]
  29. double v2 = 0.0;
  30. double s1 = 0.0; // droga [m]
  31. double s2 = 0.0;
  32.  
  33. for(double t=0; t<Tmax; t+=dt) {
  34. f1 = Faero(S_1, Cx1, v1); // opor liczony dla predkosci z poprzedniego kroku
  35. f2 = Faero(S_2, Cx2, v2);
  36. a1 = (m1*g - f1) / m1; // przyspieszenie = (ciezar - opor) / mase
  37. a2 = (m2*g - f2) / m2;
  38. double v1p = v1; // predkosc poczatkowa w kroku - do policzenia sredniej
  39. double v2p = v2;
  40. v1 += a1*dt; // predkosc wzrasta o 'przyspieszenie * czas_kroku'
  41. v2 += a2*dt;
  42. s1 += (v1p + v1)/2 * dt; // droga wzrasta o 'sredna_predkosc * czas_kroku'
  43. s2 += (v2p + v2)/2 * dt;
  44. printf("%3.2fs f[%6.2f,%6.2f] a[%4.2f,%4.2f] v[%5.2f,%5.2f] s[%5.2f,%5.2f]\n",
  45. t+dt, f1,f2, a1,a2, v1,v2, s1,s2);
  46. }
  47.  
  48. return 0;
  49. }
  50.  
  51.  
  52.  
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
0.10s f[  0.00,  0.00] a[9.81,9.81] v[ 0.98, 0.98] s[ 0.05, 0.05]
0.20s f[  0.00,  0.00] a[9.81,9.81] v[ 1.96, 1.96] s[ 0.20, 0.20]
0.30s f[  0.00,  0.00] a[9.80,9.81] v[ 2.94, 2.94] s[ 0.44, 0.44]
0.40s f[  0.00,  0.00] a[9.79,9.81] v[ 3.92, 3.92] s[ 0.78, 0.78]
0.50s f[  0.01,  0.01] a[9.78,9.81] v[ 4.90, 4.90] s[ 1.23, 1.23]
0.60s f[  0.01,  0.01] a[9.76,9.80] v[ 5.88, 5.88] s[ 1.76, 1.77]
0.70s f[  0.01,  0.01] a[9.75,9.80] v[ 6.85, 6.86] s[ 2.40, 2.40]
0.80s f[  0.02,  0.02] a[9.72,9.80] v[ 7.82, 7.84] s[ 3.13, 3.14]
0.90s f[  0.02,  0.02] a[9.70,9.79] v[ 8.79, 8.82] s[ 3.97, 3.97]
1.00s f[  0.03,  0.03] a[9.67,9.79] v[ 9.76, 9.80] s[ 4.89, 4.90]
1.10s f[  0.04,  0.04] a[9.63,9.78] v[10.72,10.78] s[ 5.92, 5.93]
1.20s f[  0.04,  0.04] a[9.59,9.78] v[11.68,11.76] s[ 7.04, 7.06]
1.30s f[  0.05,  0.05] a[9.55,9.77] v[12.64,12.73] s[ 8.25, 8.28]
1.40s f[  0.06,  0.06] a[9.51,9.76] v[13.59,13.71] s[ 9.56, 9.61]
1.50s f[  0.07,  0.07] a[9.46,9.76] v[14.53,14.69] s[10.97,11.03]
1.60s f[  0.08,  0.08] a[9.41,9.75] v[15.48,15.66] s[12.47,12.54]
1.70s f[  0.09,  0.09] a[9.36,9.74] v[16.41,16.64] s[14.07,14.16]
1.80s f[  0.10,  0.10] a[9.30,9.73] v[17.34,17.61] s[15.75,15.87]
1.90s f[  0.11,  0.12] a[9.25,9.72] v[18.27,18.58] s[17.53,17.68]
2.00s f[  0.13,  0.13] a[9.18,9.71] v[19.19,19.55] s[19.41,19.59]
2.10s f[  0.14,  0.14] a[9.12,9.70] v[20.10,20.52] s[21.37,21.59]
2.20s f[  0.15,  0.16] a[9.05,9.69] v[21.00,21.49] s[23.42,23.69]
2.30s f[  0.17,  0.17] a[8.98,9.68] v[21.90,22.46] s[25.57,25.89]
2.40s f[  0.18,  0.19] a[8.91,9.66] v[22.79,23.42] s[27.80,28.18]
2.50s f[  0.19,  0.21] a[8.84,9.65] v[23.68,24.39] s[30.13,30.57]
2.60s f[  0.21,  0.22] a[8.76,9.64] v[24.55,25.35] s[32.54,33.06]
2.70s f[  0.23,  0.24] a[8.68,9.62] v[25.42,26.32] s[35.04,35.64]
2.80s f[  0.24,  0.26] a[8.60,9.61] v[26.28,27.28] s[37.62,38.32]
2.90s f[  0.26,  0.28] a[8.52,9.60] v[27.13,28.24] s[40.29,41.10]
3.00s f[  0.28,  0.30] a[8.43,9.58] v[27.97,29.19] s[43.05,43.97]
3.10s f[  0.29,  0.32] a[8.34,9.56] v[28.81,30.15] s[45.89,46.94]
3.20s f[  0.31,  0.34] a[8.25,9.55] v[29.63,31.11] s[48.81,50.00]
3.30s f[  0.33,  0.36] a[8.16,9.53] v[30.45,32.06] s[51.81,53.16]
3.40s f[  0.35,  0.39] a[8.07,9.51] v[31.26,33.01] s[54.90,56.41]
3.50s f[  0.37,  0.41] a[7.98,9.50] v[32.05,33.96] s[58.06,59.76]
3.60s f[  0.39,  0.43] a[7.88,9.48] v[32.84,34.91] s[61.31,63.20]
3.70s f[  0.40,  0.46] a[7.79,9.46] v[33.62,35.85] s[64.63,66.74]
3.80s f[  0.42,  0.48] a[7.69,9.44] v[34.39,36.80] s[68.03,70.38]
3.90s f[  0.44,  0.51] a[7.59,9.42] v[35.15,37.74] s[71.51,74.10]
4.00s f[  0.46,  0.53] a[7.49,9.40] v[35.90,38.68] s[75.06,77.92]
4.10s f[  0.48,  0.56] a[7.39,9.38] v[36.64,39.62] s[78.69,81.84]
4.20s f[  0.50,  0.59] a[7.29,9.36] v[37.37,40.55] s[82.39,85.85]
4.30s f[  0.52,  0.62] a[7.19,9.34] v[38.09,41.49] s[86.16,89.95]
4.40s f[  0.54,  0.65] a[7.09,9.31] v[38.80,42.42] s[90.01,94.14]
4.50s f[  0.56,  0.67] a[6.99,9.29] v[39.50,43.35] s[93.92,98.43]
4.60s f[  0.58,  0.70] a[6.89,9.27] v[40.18,44.27] s[97.91,102.81]
4.70s f[  0.61,  0.74] a[6.78,9.24] v[40.86,45.20] s[101.96,107.29]
4.80s f[  0.63,  0.77] a[6.68,9.22] v[41.53,46.12] s[106.08,111.85]
4.90s f[  0.65,  0.80] a[6.58,9.20] v[42.19,47.04] s[110.26,116.51]
5.00s f[  0.67,  0.83] a[6.47,9.17] v[42.83,47.96] s[114.51,121.26]
5.10s f[  0.69,  0.86] a[6.37,9.15] v[43.47,48.87] s[118.83,126.10]
5.20s f[  0.71,  0.90] a[6.27,9.12] v[44.10,49.78] s[123.21,131.03]
5.30s f[  0.73,  0.93] a[6.16,9.10] v[44.71,50.69] s[127.65,136.06]
5.40s f[  0.75,  0.96] a[6.06,9.07] v[45.32,51.60] s[132.15,141.17]
5.50s f[  0.77,  1.00] a[5.96,9.04] v[45.92,52.50] s[136.71,146.38]
5.60s f[  0.79,  1.03] a[5.86,9.01] v[46.50,53.41] s[141.33,151.67]
5.70s f[  0.81,  1.07] a[5.76,8.99] v[47.08,54.30] s[146.01,157.06]
5.80s f[  0.83,  1.11] a[5.65,8.96] v[47.64,55.20] s[150.75,162.53]
5.90s f[  0.85,  1.14] a[5.55,8.93] v[48.20,56.09] s[155.54,168.10]
6.00s f[  0.87,  1.18] a[5.45,8.90] v[48.74,56.98] s[160.39,173.75]
6.10s f[  0.89,  1.22] a[5.36,8.87] v[49.28,57.87] s[165.29,179.50]
6.20s f[  0.91,  1.26] a[5.26,8.84] v[49.81,58.76] s[170.24,185.33]
6.30s f[  0.93,  1.29] a[5.16,8.81] v[50.32,59.64] s[175.25,191.25]
6.40s f[  0.95,  1.33] a[5.06,8.78] v[50.83,60.52] s[180.31,197.25]
6.50s f[  0.97,  1.37] a[4.97,8.75] v[51.32,61.39] s[185.41,203.35]
6.60s f[  0.99,  1.41] a[4.87,8.72] v[51.81,62.26] s[190.57,209.53]
6.70s f[  1.01,  1.45] a[4.78,8.69] v[52.29,63.13] s[195.78,215.80]
6.80s f[  1.03,  1.49] a[4.68,8.66] v[52.76,64.00] s[201.03,222.16]
6.90s f[  1.04,  1.54] a[4.59,8.63] v[53.22,64.86] s[206.33,228.60]
7.00s f[  1.06,  1.58] a[4.50,8.60] v[53.67,65.72] s[211.67,235.13]
7.10s f[  1.08,  1.62] a[4.41,8.56] v[54.11,66.58] s[217.06,241.75]
7.20s f[  1.10,  1.66] a[4.32,8.53] v[54.54,67.43] s[222.49,248.45]
7.30s f[  1.12,  1.71] a[4.23,8.50] v[54.96,68.28] s[227.97,255.23]
7.40s f[  1.13,  1.75] a[4.15,8.47] v[55.38,69.13] s[233.48,262.10]
7.50s f[  1.15,  1.79] a[4.06,8.43] v[55.78,69.97] s[239.04,269.06]
7.60s f[  1.17,  1.84] a[3.98,8.40] v[56.18,70.81] s[244.64,276.10]
7.70s f[  1.18,  1.88] a[3.89,8.36] v[56.57,71.65] s[250.28,283.22]
7.80s f[  1.20,  1.92] a[3.81,8.33] v[56.95,72.48] s[255.95,290.42]
7.90s f[  1.22,  1.97] a[3.73,8.29] v[57.32,73.31] s[261.67,297.71]
8.00s f[  1.23,  2.02] a[3.65,8.26] v[57.69,74.13] s[267.42,305.09]
8.10s f[  1.25,  2.06] a[3.57,8.22] v[58.05,74.96] s[273.21,312.54]
8.20s f[  1.26,  2.11] a[3.49,8.19] v[58.39,75.78] s[279.03,320.08]
8.30s f[  1.28,  2.15] a[3.42,8.15] v[58.74,76.59] s[284.88,327.70]
8.40s f[  1.29,  2.20] a[3.34,8.12] v[59.07,77.40] s[290.77,335.39]
8.50s f[  1.31,  2.25] a[3.27,8.08] v[59.40,78.21] s[296.70,343.18]
8.60s f[  1.32,  2.29] a[3.19,8.05] v[59.72,79.02] s[302.65,351.04]
8.70s f[  1.34,  2.34] a[3.12,8.01] v[60.03,79.82] s[308.64,358.98]
8.80s f[  1.35,  2.39] a[3.05,7.97] v[60.33,80.61] s[314.66,367.00]
8.90s f[  1.37,  2.44] a[2.98,7.94] v[60.63,81.41] s[320.71,375.10]
9.00s f[  1.38,  2.49] a[2.92,7.90] v[60.92,82.20] s[326.79,383.28]
9.10s f[  1.39,  2.53] a[2.85,7.86] v[61.21,82.98] s[332.89,391.54]
9.20s f[  1.40,  2.58] a[2.79,7.82] v[61.49,83.77] s[339.03,399.88]
9.30s f[  1.42,  2.63] a[2.72,7.79] v[61.76,84.54] s[345.19,408.29]
9.40s f[  1.43,  2.68] a[2.66,7.75] v[62.03,85.32] s[351.38,416.79]
9.50s f[  1.44,  2.73] a[2.60,7.71] v[62.29,86.09] s[357.59,425.36]
9.60s f[  1.45,  2.78] a[2.54,7.67] v[62.54,86.86] s[363.84,434.00]
9.70s f[  1.47,  2.83] a[2.48,7.63] v[62.79,87.62] s[370.10,442.73]
9.80s f[  1.48,  2.88] a[2.42,7.60] v[63.03,88.38] s[376.39,451.53]
9.90s f[  1.49,  2.93] a[2.36,7.56] v[63.27,89.14] s[382.71,460.40]
10.00s f[  1.50,  2.98] a[2.31,7.52] v[63.50,89.89] s[389.05,469.35]
10.10s f[  1.51,  3.03] a[2.25,7.48] v[63.72,90.64] s[395.41,478.38]