float AirqualityGp2y10::aver(int num) //єЇКэ¶ЁТе { float sum=0,temp; float sum1[num]; int i = 0,j = 0; for(i=0;i<num;i++) { sum1[i]=AirDensity();///// } for(i=0;i<num;i++) { for(j=i+1;j<num;j++) { if(sum1[i]>sum1[j]) { temp=sum1[i]; sum1[i]=sum1[j]; sum1[j]=temp; } } } for(i=0;i<num;i++) sum+=sum1[i]; return(sum/num); }
static bool test_isa_density(const fixed alt, const fixed prat) { fixed p0 = AirDensity(alt); if (verbose) { printf("%g\n", double(p0)); } return fabs(p0/fixed(1.225)-prat)<fixed(0.001); }
// Function to compute the sustainable speed in KM/H from input params and a // bunch of real world constants. // Relies upon cubic root finder. // The bicycle related equations came from http://kreuzotter.de/english/espeed.htm, // The pressure and density equations came from wikipedia. double computeInstantSpeed(double weightKG, double slope, double altitude, // altitude in meters double pw, // watts double crr, // rolling resistance double Cm, // powertrain loss double Cd, // coefficient of drag double A, // frontal area (m2) double T) // temp in kelvin { double vs = 0; // Return value double sl = slope / 100; // 10% = 0.1 // Compute velocity using equations from http://kreuzotter.de/english/espeed.htm const double CrV = 0.1; // Coefficient for velocity - dependent dynamic rolling resistance, here approximated with 0.1 double CrVn = CrV * cos(sl); // Coefficient for the dynamic rolling resistance, normalized to road inclination; CrVn = CrV*cos(slope) const double W = 0; // Windspeed double Hnn = altitude; // Altitude above sea level (m). double m = weightKG; double Rho = AirDensity(Hnn, T); double Beta = atan(sl); double cosBeta = cos(Beta); double sinBeta = sin(Beta); double Frg = s_g0 * m * (crr * cosBeta + sinBeta); // Home Rolled cubic solver: // v^3 + v^2 * 2 * (W + CrVn/(Cd *A*Rho)) + V*(W^2 + (2*Frg/(Cd*A*Rho))) - (2*P)/(Cm*Cd*A*Rho) = 0; // // A = 1 (monic) // B = 2 * (W + CrVn / (Cd*A*Rho)) // C = (W ^ 2 + (2 * Frg / (Cd*A*Rho))) // D = -(2 * P) / (Cm*Cd*A*Rho) double CdARho = Cd * A * Rho; double a = 1; double b = 2 * (W + CrVn / (CdARho)); double c = (W * W + (2 * Frg / (CdARho))); double d = -(2 * pw) / (Cm * CdARho); vs = 0; { Roots r = BlinnCubicSolver(a, b, c, d); // Iterate across roots for one that provides a positive velocity, // otherwise try and choose a positive one that is closest to zero, // finally tolerate a negative one thats closest to zero. for (unsigned u = 0; u < r.resultcount(); u++) { double t = r.result(u).x / r.result(u).w; if (vs == 0) vs = t; else if (vs > 0) { if (t > 0 && t < vs) vs = t; } else { if (t > vs) vs = t; } } } #if 0 // Now to test we run the equation the other way and compute power needed to sustain computed speed. // A properly computed v should very closely predict the power needed to sustain that speed. double testPw = Cm * vs * (Cd * A * Rho / 2 * (vs + W)*(vs + W) + Frg + vs * CrVn); double delta = fabs(testPw - pw); #endif vs *= 3.6; // m/s to km/h. return vs; }
// divide TAS by this number to get IAS double AirDensityRatio(double altitude) { double rho = AirDensity(altitude); double rho_rat = sqrt(1.225/rho); return rho_rat; }
// Air Speed from air density, humidity, temperature and absolute pressure double TrueAirSpeed( double delta_press, double hr, double temp, double abs_press ) { double rho = AirDensity(hr,temp,abs_press); return sqrt(2 * delta_press / rho); }
fixed AtmosphericPressure::AirDensityRatio(const fixed altitude) { return sqrt(isa_sea_level_density / AirDensity(altitude)); }