Exemplo n.º 1
0
        /// <summary>
        /// Finds the zeros of a function using a brute force approach.
        /// </summary>
        /// <param name="_input">Input string.</param>
        public static void NumericalZeros(Input _input)
        {
            int tol = 100;

            //Throws an error if input is not correct
            if (_input.Args.Length == 0)
            {
                throw new Errors.MissingFunctionException();
            }

            //Evaluates the function
            FunctionBaseCore FB = CodeBaseCore.CreateFunction(_input.Args[0]);
            NFunctionalEqCore FE = new NFunctionalEqCore(FB, FunctionBounds.CreateBounds(_input.Args), false);

            //Gets tolerance level if defined
            if (_input.Modifiers.Length > 0)
            {
                foreach (string mods in _input.Modifiers)
                {
                    if (mods.StartsWith("-t:"))
                    {
                        tol = Convert.ToInt32(mods.Remove(0, 3));
                    }
                }
            }

            //Continues process until tolerance is reached
            for (int i = 1; i < tol; i++)
            {
                //Numerically evaluates the function across the boundary conditions
                List<List<float>> curve = FE.evalFlat();
                List<float> min = curve[0];

                //Finds the point which is closest to zero
                foreach (List<float> x in curve.Skip(1))
                {
                    min = CompareZero(x, min);
                }
                //To be completed...
            }
        }
Exemplo n.º 2
0
        //Performs numerical integration
        private static float NIntCore(FunctionBounds Bounds, FunctionBaseCore FB)
        {
            //gets a new N space evaluation
            NFunctionalEqCore FE = new NFunctionalEqCore(FB, Bounds, true);

            float dv = FE.bounds.Aggregate(1.0f, (total, next) => total * next.Step);
            float val = FE.evalFlat().Sum(x => x[x.Count -1] * dv);

            //foreach(List<float> item in FE.evalFlat().)
            //{
            //    //for (int i = 0; i < FE.bounds.Length; i++)
            //    //{
            //    //    val += item[item.Count - 1] * (float)FE.bounds[i].Step;
            //    //}

            //    val += dv*item[item.Count-1];
            //}

            return val;
        }