/** This program calculates the total energy expended by a rocket fighting atmospheric drag. */ use StandardAtmosphere.frink getDensity[altitude] := { [temp, pressure] = StandardAtmosphere.getTemperatureAndPressure[altitude] return StandardAtmosphere.getDensity[altitude, temp, pressure] } getDensityVelocitySquaredProduct[altitude, velocity] := { getDensity[altitude] * velocity^2 } altitude = 0 ft v = 0 mph mass = 13500 kg // Full mass of X-15B, empty is 4500 kg Frocket = 262.5/1 kN // Thrust of X-15B target = 350 km Cd = 0.10 A = 33 ft^2 timestep = .01 s t = 0 s Esum = 0 J while (altitude < target) { density = getDensity[altitude] Fdrag = 1/2 density v^2 A Cd weight = G earthmass mass / (altitude + earthradius)^2 // Correct weight for decreasing gravity Fup = Frocket - Fdrag - weight a = Fup/mass // Actual upward acceleration vnew = v + a timestep vave = (v + vnew) / 2 // Average velocity during timestep stepdist = vave * timestep // Distance traveled in timestep Esum = Esum + Fdrag * stepdist // Energy lost due to drag println[format[t,"s",2] + "\t" + format[altitude,"km", 3] + "\t" + formatSig[v, "mach", 3] + "\t" + formatSig[a,"gee",3] + "\t" + formatSig[Fdrag, "lbf", 6] + "\t" + formatEng[Esum, "J", 5]] v = vnew altitude = altitude + stepdist t = t + timestep }