Пример #1
0
        /// <summary>
        /// Calculates value of function for given point.
        /// </summary>
        /// <param name="coordinates">Point for which we want to calculate function value.</param>
        /// <returns>Value of function.</returns>

        public override double CalculateValue(params double[] coordinates)
        {
            if (coordinates.Length == 1 && parameters != null)
            {
                FunctionOptimization.Expression expression0 = parameters[0];
                FunctionOptimization.Expression expression1 = parameters[1];
                double x0 = expression0(coordinates[0]);
                double x1 = expression1(coordinates[0]);
                return(Math.Pow(x0 - 4, 2) + 4 * Math.Pow(x1 - 2, 2));
            }
            else
            {
                return(Math.Pow(coordinates[0] - 4, 2) + 4 * Math.Pow(coordinates[1] - 2, 2));
            }
        }
        /// <summary>
        /// Sets parameters of function.
        /// </summary>
        /// <param name="index">Index of parameters field.</param>
        /// <param name="expression">Expression used as a parameter.</param>

        public void SetParameters(int index, FunctionOptimization.Expression expression)
        {
            parameters[index] = expression;
        }