public virtual void AddTrialStep() { int k = extrapolator.Count; double y = TrialStep(N[k]); extrapolator.Add(MoreMath.Sqr(1.0 / N[k]), y); double norm = Math.Abs(y); double tol = settings.ComputePrecision(norm); double error = extrapolator.Error; this.Ratio = error / tol; }
public void AddTrialStep() { int k = yExtrapolator.Count; double y1, yp1; TrialStep(N[k], out y1, out yp1); yExtrapolator.Add(MoreMath.Sqr(1.0 / N[k]), y1); ypExtrapolator.Add(MoreMath.Sqr(1.0 / N[k]), yp1); double yTol = settings.ComputePrecision(Math.Abs(yExtrapolator.Value)); double yError = yExtrapolator.Error; double yRatio = yError / yTol; double ypTol = settings.ComputePrecision(Math.Abs(ypExtrapolator.Value)); double ypError = ypExtrapolator.Error; double ypRatio = ypError / ypTol; this.Ratio = Math.Max(yRatio, ypRatio); }
public override void Step() { yExtrapolator.Clear(); ypExtrapolator.Clear(); int work = 1; double bestEfficiency = 0.0; double bestFactor = 1.0; int bestK = -1; for (int k = 0; k < N.Length; k++) { double y1, yp1; TrialStep(N[k], out y1, out yp1); yExtrapolator.Add(MoreMath.Sqr(1.0 / N[k]), y1); ypExtrapolator.Add(MoreMath.Sqr(1.0 / N[k]), yp1); work += N[k]; if (k < 1) { continue; } UncertainValue yEstimate = yExtrapolator.Estimate; double error = yEstimate.Uncertainty; double tol = Settings.ComputePrecision(yEstimate.Value); double factor = Math.Pow(tol / error, 1.0 / (2 * k + 1)); double efficiency = factor / work; if (((k + 1) < N.Length) && (efficiency > bestEfficiency)) { bestEfficiency = efficiency; bestFactor = factor; bestK = k; } if (error <= tol) { X += DeltaX; Y = yEstimate.Value; YPrime = ypExtrapolator.Estimate.Value; YPrimePrime = Evaluate(X, Y); if ((k + 2) < N.Length) { double extrapolatedError = MoreMath.Sqr(1.0 * N[0] / N[k + 1]) * error; int extrapolatedWork = work + N[k + 1]; double extrapolatedFactor = Math.Pow(tol / extrapolatedError, 1.0 / (2 * k + 3)); double extrapolatedEfficiency = extrapolatedFactor / extrapolatedWork; if (extrapolatedEfficiency > bestEfficiency) { bestEfficiency = extrapolatedEfficiency; bestFactor = extrapolatedFactor; bestK = k + 1; } } break; } } if (bestFactor < 0.2) { bestFactor = 0.2; } if (bestFactor > 5.0) { bestFactor = 5.0; } DeltaX *= 0.9375 * bestFactor; }