/// This method assumes that the range of the argument has been checked. /// Computation is made using the Newton zero finder. /// @return double the value for which the distribution function /// is equal to x. /// @param x double value of the distribution function. protected virtual double PrivateInverseDistributionValue(double x) { OffsetDistributionFunction distribution = new OffsetDistributionFunction(this, x); NewtonZeroFinder zeroFinder = new NewtonZeroFinder(distribution, this, this.Average); zeroFinder.DesiredPrecision = DhbMath.DefaultNumericalPrecision; zeroFinder.Evaluate(); return(zeroFinder.Result); }
/// @param desiredPrecision double /// @return double[] public double[] Roots(double desiredPrecision) { PolynomialFunction dp = this.Derivative(); double start = 0; Random random = new Random(); while (Math.Abs(dp.Value(start)) < desiredPrecision) { start = random.NextDouble(); } PolynomialFunction p = this; NewtonZeroFinder rootFinder = new NewtonZeroFinder(this, dp, start); rootFinder.DesiredPrecision = desiredPrecision; List <double> rootCollection = new List <double>(Degree); while (true) { rootFinder.Evaluate(); if (!rootFinder.HasConverged) { break; } double r = rootFinder.Result; rootCollection.Add(r); p = p.Deflate(r); if (p.Degree == 0) { break; } rootFinder.Function = p; try { rootFinder.Derivative = p.Derivative(); } catch (ArgumentException) { }; } return(rootCollection.ToArray()); }
/// @param desiredPrecision double /// @return double[] public double[] Roots(double desiredPrecision) { PolynomialFunction dp = this.Derivative(); double start = 0; Random random = new Random(); while (System.Math.Abs(dp.Value(start)) < desiredPrecision) start = random.NextDouble(); PolynomialFunction p = this; NewtonZeroFinder rootFinder = new NewtonZeroFinder(this, dp, start); rootFinder.DesiredPrecision = desiredPrecision; List<double> rootCollection = new List<double>(Degree); while (true) { rootFinder.Evaluate(); if (!rootFinder.HasConverged) break; double r = rootFinder.Result; rootCollection.Add(r); p = p.Deflate(r); if (p.Degree == 0) break; rootFinder.Function = p; try { rootFinder.Derivative = p.Derivative(); } catch (ArgumentException) { } ; } return rootCollection.ToArray(); }
/// This method assumes that the range of the argument has been checked. /// Computation is made using the Newton zero finder. /// @return double the value for which the distribution function /// is equal to x. /// @param x double value of the distribution function. protected virtual double PrivateInverseDistributionValue(double x) { OffsetDistributionFunction distribution = new OffsetDistributionFunction(this, x); NewtonZeroFinder zeroFinder = new NewtonZeroFinder(distribution, this, this.Average); zeroFinder.DesiredPrecision = DhbMath.DefaultNumericalPrecision; zeroFinder.Evaluate(); return zeroFinder.Result; }