Esempio n. 1
0
 /// <summary>
 /// Compute the n-th stage integral of trapezoid rule. This function
 /// should only be called by API <code>integrate()</code> in the package.
 /// To save time it does not verify arguments - caller does.
 /// <para>
 /// The interval is divided equally into 2^n sections rather than an
 /// arbitrary m sections because this configuration can best utilize the
 /// already computed values.</para>
 /// </summary>
 /// <param name="baseIntegrator"> integrator holding integration parameters </param>
 /// <param name="n"> the stage of 1/2 refinement, n = 0 is no refinement </param>
 /// <returns> the value of n-th stage integral </returns>
 /// <exception cref="TooManyEvaluationsException"> if the maximal number of evaluations
 /// is exceeded. </exception>
 internal virtual double Stage(BaseAbstractUnivariateIntegrator baseIntegrator, int n)
 {
     if (n == 0)
     {
         double max = baseIntegrator.Max;
         double min = baseIntegrator.Min;
         this.s = 0.5 * (max - min) * (baseIntegrator.ComputeObjectiveValue(min) + baseIntegrator.ComputeObjectiveValue(max));
         return(this.s);
     }
     else
     {
         long   np  = 1L << (n - 1); // number of new points in this stage
         double sum = 0;
         double max = baseIntegrator.Max;
         double min = baseIntegrator.Min;
         // spacing between adjacent new points
         double spacing = (max - min) / np;
         double x       = min + 0.5 * spacing; // the first new point
         for (long i = 0; i < np; i++)
         {
             sum += baseIntegrator.ComputeObjectiveValue(x);
             x   += spacing;
         }
         // add the new sum to previously calculated result
         this.s = 0.5 * (this.s + sum * spacing);
         return(this.s);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Compute the n-th stage integral of trapezoid rule. This function
        /// should only be called by API <code>integrate()</code> in the package.
        /// To save time it does not verify arguments - caller does.
        /// <para>
        /// The interval is divided equally into 2^n sections rather than an
        /// arbitrary m sections because this configuration can best utilize the
        /// already computed values.</para>
        /// </summary>
        /// <param name="baseIntegrator"> integrator holding integration parameters </param>
        /// <param name="n"> the stage of 1/2 refinement, n = 0 is no refinement </param>
        /// <returns> the value of n-th stage integral </returns>
        /// <exception cref="TooManyEvaluationsException"> if the maximal number of evaluations
        /// is exceeded. </exception>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: double stage(final BaseAbstractUnivariateIntegrator baseIntegrator, final int n) throws org.apache.commons.math3.exception.TooManyEvaluationsException
        internal virtual double Stage(BaseAbstractUnivariateIntegrator baseIntegrator, int n)
        {
            if (n == 0)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double max = baseIntegrator.getMax();
                double max = baseIntegrator.GetMax();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double min = baseIntegrator.getMin();
                double min = baseIntegrator.GetMin();
                s = 0.5 * (max - min) * (baseIntegrator.ComputeObjectiveValue(min) + baseIntegrator.ComputeObjectiveValue(max));
                return(s);
            }
            else
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long np = 1L << (n-1);
                long   np  = 1L << (n - 1); // number of new points in this stage
                double sum = 0;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double max = baseIntegrator.getMax();
                double max = baseIntegrator.GetMax();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double min = baseIntegrator.getMin();
                double min = baseIntegrator.GetMin();
                // spacing between adjacent new points
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double spacing = (max - min) / np;
                double spacing = (max - min) / np;
                double x       = min + 0.5 * spacing; // the first new point
                for (long i = 0; i < np; i++)
                {
                    sum += baseIntegrator.ComputeObjectiveValue(x);
                    x   += spacing;
                }
                // add the new sum to previously calculated result
                s = 0.5 * (s + sum * spacing);
                return(s);
            }
        }