Ejemplo n.º 1
0
        /// <summary>
        /// Returns the value of a derived function.
        /// </summary>
        /// <param name="y">Function vector</param>
        /// <param name="index">Index of argument</param>
        /// <param name="h">Step</param>
        /// <param name="order">Order</param>
        /// <returns>float precision floating point number</returns>
        public float Compute(float[] y, int index, float h, int order)
        {
            // exception
            if (order > this.points)
            {
                throw new Exception("The order of the derivative cannot be greater than the number of interpolation points");
            }
            if (order < 0)
            {
                throw new Exception("The derivative order cannot be less than 0");
            }

            // Create the interpolation points
            int length = this.points + 1;

            float[,] coefficients = Differentation.GetCoefficients(length);
            float sum = 0.0f;

            // do job
            for (int i = 0, center = 0; i < length; i++)
            {
                sum += coefficients[order, i] * y[index + i];
                center++;
            }

            // result
            return(sum / (float)Math.Pow(h, order));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the value of a derived function.
        /// </summary>
        /// <param name="function">Continuous function delegate</param>
        /// <param name="x">Argument value</param>
        /// <param name="h">Step</param>
        /// <param name="order">Order</param>
        /// <returns>Complex number</returns>
        public Complex32 Compute(IComplex function, Complex32 x, Complex32 h, int order)
        {
            // exception
            if (order > this.points)
            {
                throw new Exception("The order of the derivative cannot be greater than the number of interpolation points");
            }
            if (order < 0)
            {
                throw new Exception("The derivative order cannot be less than 0");
            }

            // Create the interpolation points
            int length = this.points + 1;

            float[,] coefficients = Differentation.GetCoefficients(length);
            Complex32 sum = 0.0;

            // do job
            for (int i = 0, center = 0; i < length; i++)
            {
                sum += coefficients[order, i] * function(x + center * h);
                center++;
            }

            // result
            return(sum / Maths.Pow(h, order));
        }