Пример #1
0
        /// <summary>
        /// Clones itself
        /// </summary>
        /// <returns>A clone</returns>
        public object Clone()
        {
            ElementaryRoot r = new ElementaryRoot();

            r.arity = arity;
            return(r);
        }
Пример #2
0
        /// <summary>
        /// Calculates derivation
        /// </summary>
        /// <param name="tree">The function for derivation calculation</param>
        /// <param name="variableName">Name of variable</param>
        /// <returns>The derivation</returns>
        public ObjectFormulaTree Derivation(ObjectFormulaTree tree, string variableName)
        {
            Double a = 0;

            ObjectFormulaTree[] fc = new ObjectFormulaTree[2];
            ObjectFormulaTree[] fd = new ObjectFormulaTree[2];
            for (int i = 0; i < 2; i++)
            {
                fc[i] = tree[i];
                fd[i] = fc[i].Derivation(variableName);
            }
            List <ObjectFormulaTree> list    = new List <ObjectFormulaTree>();
            IObjectOperation         nom     = new ElementaryBinaryOperation('-', new object[] { a, a });
            List <ObjectFormulaTree> nomList = new List <ObjectFormulaTree>();

            for (int i = 0; i < 2; i++)
            {
                List <ObjectFormulaTree> l = new List <ObjectFormulaTree>();
                l.Add(fc[1 - i]);
                l.Add(fd[i]);
                IObjectOperation o = new ElementaryBinaryOperation('*', new object[] { a, a });
                nomList.Add(new ObjectFormulaTree(o, l));
            }
            list.Add(new ObjectFormulaTree(nom, nomList));
            List <ObjectFormulaTree> plusList = new List <ObjectFormulaTree>();

            for (int i = 0; i < 2; i++)
            {
                List <ObjectFormulaTree> l = new List <ObjectFormulaTree>();
                l.Add(fc[i]);
                l.Add(new ObjectFormulaTree(new ElementaryRealConstant(2), new List <ObjectFormulaTree>()));
                IObjectOperation o = ElementaryFunctionsCreator.Object.GetPowerOperation(a, a);
                plusList.Add(new ObjectFormulaTree(o, l));
            }
            IObjectOperation         plusOp    = new ElementaryBinaryOperation('+', new object[] { a, a });
            IObjectOperation         denomOp   = new ElementaryRoot();
            List <ObjectFormulaTree> denomList = new List <ObjectFormulaTree>();

            // denomList.Add(new ObjectFormulaTree(plusOp, plusList));
            //list.Add(new ObjectFormulaTree(new ElementaryRoot(), denomList));
            list.Add(new ObjectFormulaTree(plusOp, plusList));
            return(new ObjectFormulaTree(ElementaryFraction.Object, list));
        }