| 1178 | } |
| 1179 | } |
| 1180 | static double IntegrateInverseInterpolated(double y1, double y2, double time, bool logarithmic) |
| 1181 | { |
| 1182 | // Calculates: integral(1 / interpolate(y1, y2, x), x = 0 .. time) |
| 1183 | // This one is a bit harder. Linear: |
| 1184 | // http://www.wolframalpha.com/input/?i=integrate+1%2F%28y1*%28T-x%29%2FT%2By2*x%2FT%29+from+0+to+T |
| 1185 | // Logarithmic: |
| 1186 | // http://www.wolframalpha.com/input/?i=integrate+1%2F%2810%5E%28log10%28y1%29*%28T-x%29%2FT%2Blog10%28y2%29*x%2FT%29%29+from+0+to+T |
| 1187 | // Here both cases need a special case for y1 == y2. The threshold is 1.0e5 again, this is still the |
| 1188 | // best value in both cases. |
| 1189 | double l = log(y1 / y2); |
| 1190 | if(fabs(l) < 1.0e-5) // fall back to average |
| 1191 | return 2.0 / (y1 + y2) * time; |
| 1192 | if(logarithmic) |
| 1193 | return (y1 - y2) / (l * y1 * y2) * time; |
| 1194 | else |
| 1195 | return l / (y1 - y2) * time; |
| 1196 | } |
| 1197 | static double SolveIntegrateInverseInterpolated(double y1, double y2, double time, double area, bool logarithmic) |
| 1198 | { |
| 1199 | // Calculates: solve (integral(1 / interpolate(y1, y2, x), x = 0 .. res) = area) for res |
no outgoing calls
no test coverage detected