예제 #1
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)
        {
            if (deriv)
            {
                throw new Exception("Could not calculate second derivation");
            }
            ElementaryUnaryOperation der = new ElementaryUnaryOperation(unary, index);

            der.deriv = true;
            List <ObjectFormulaTree> list   = new List <ObjectFormulaTree>();
            List <ObjectFormulaTree> lFirst = new List <ObjectFormulaTree>();

            lFirst.Add(tree[0]);//.Clone() as ObjectFormulaTree);
            list.Add(new ObjectFormulaTree(der, lFirst));
            list.Add(tree[0].Derivation(variableName));
            Double a = 0;

            return(new ObjectFormulaTree(new ElementaryBinaryOperation('*', new object[] { a, a }), list));
        }
예제 #2
0
 /// <summary>
 /// Sets unary table on tree
 /// </summary>
 /// <param name="tree">Tree to set unary</param>
 /// <param name="unary">Unary table</param>
 public static void SetUnary(ObjectFormulaTree tree, Dictionary <int, IUnary> unary)
 {
     if (tree.Operation is ElementaryUnaryOperation)
     {
         ElementaryUnaryOperation op = tree.Operation as ElementaryUnaryOperation;
         op.Unary = unary;
     }
     else if (tree.Operation is ArrayOperation)
     {
         ArrayOperation ao = tree.Operation as ArrayOperation;
         if (ao.SingleOperation is ElementaryUnaryOperation)
         {
             ElementaryUnaryOperation eo = ao.SingleOperation as ElementaryUnaryOperation;
             eo.Unary = unary;
         }
     }
     for (int i = 0; i < tree.Count; i++)
     {
         SetUnary(tree[i], unary);
     }
 }
예제 #3
0
        /// <summary>
        /// Gets unary table of tree
        /// </summary>
        /// <param name="tree">The tree</param>
        /// <param name="table">The table</param>
        public static void GetUnaryTable(ObjectFormulaTree tree, Dictionary <int, IUnary> table)
        {
            if (tree.Operation is ElementaryUnaryOperation)
            {
                ElementaryUnaryOperation op = tree.Operation as ElementaryUnaryOperation;
                table[op.index] = op.unary;
            }
            if (tree.Operation is ArrayOperation)
            {
                ArrayOperation   op = tree.Operation as ArrayOperation;
                IObjectOperation so = op.SingleOperation;
                if (so is ElementaryUnaryOperation)
                {
                    ElementaryUnaryOperation sop = so as ElementaryUnaryOperation;
                    table[sop.index] = sop.unary;
                }
            }

            for (int i = 0; i < tree.Count; i++)
            {
                GetUnaryTable(tree[i], table);
            }
        }
예제 #4
0
 /// <summary>
 /// Gets unary indexes of tree
 /// </summary>
 /// <param name="tree">The tree</param>
 /// <param name="list">List of indexes</param>
 public static void GetUnaryIndexes(ObjectFormulaTree tree, List <int> list)
 {
     try
     {
         if (tree.Operation is ElementaryUnaryOperation)
         {
             ElementaryUnaryOperation op = tree.Operation as ElementaryUnaryOperation;
             int indx = op.index;
             if (!list.Contains(indx))
             {
                 list.Add(indx);
             }
         }
         if (tree.Operation is ArrayOperation)
         {
             ArrayOperation   op = tree.Operation as ArrayOperation;
             IObjectOperation so = op.SingleOperation;
             if (so is ElementaryUnaryOperation)
             {
                 ElementaryUnaryOperation sop = so as ElementaryUnaryOperation;
                 int ind = sop.index;
                 if (!list.Contains(ind))
                 {
                     list.Add(ind);
                 }
             }
         }
         for (int i = 0; i < tree.Count; i++)
         {
             GetUnaryIndexes(tree[i], list);
         }
     }
     catch (Exception)
     {
     }
 }