Exemplo n.º 1
0
        /// <inheritdoc/>
        public override ExpNode Execute(MultiplicationOperNode node)
        {
            // TODO: Sinusoidal u substitutions
            // TODO: Constants recognitions for v
            Differentiator differentiator = new(_variable);

            // \int{u'vwx} = uvwx - \int{uv'wx} - \int{uvw'x} - \int{uvwx'}
            int partCount = node.ChildCount - 1;

            // Get u and du
            ExpNode du = node.GetChild(partCount);
            ExpNode u  = du.Clone().Execute(this);

            // Get dvs and vs
            ExpNode[] dvs = new ExpNode[partCount];
            ExpNode[] vs  = new ExpNode[partCount];
            for (int i = 0; i < partCount; i++)
            {
                vs[i]  = node.GetChild(i);
                dvs[i] = vs[i].Clone().Execute(differentiator);
            }

            AdditionOperNode aNode = new();

            // u*vs
            MultiplicationOperNode mNode = new();

            mNode.AddChild(u.Clone());
            for (int i = 0; i < partCount; i++)
            {
                mNode.AddChild(vs[i].Clone());
            }
            aNode.AddChild(mNode);

            // Combinatoric integrals
            for (int i = 0; i < partCount; i++)
            {
                IntegralOperNode intNode = new();
                mNode            = new MultiplicationOperNode();
                intNode.Variable = new VarValueNode(_variable);
                mNode.AddChild(u.Clone());
                for (int j = 0; j < partCount; j++)
                {
                    if (i == j)
                    {
                        mNode.AddChild(dvs[j].Clone());
                    }
                    else
                    {
                        mNode.AddChild(vs[j].Clone());
                    }
                }
                intNode.AddChild(mNode);
                aNode.AddChild(QuickOpers.Negative(intNode));
            }

            return(aNode);
        }
Exemplo n.º 2
0
 private static ExpNode SineTable(SineOperNode node)
 {
     return(node.SineFunction switch
     {
         SineFunction.SINE => new SineOperNode(SineFunction.COSINE)
         {
             Child = node.Child
         },
         SineFunction.COSINE => QuickOpers.Negative(new SineOperNode(SineFunction.SINE)
         {
             Child = node.Child
         }),
         _ => node,
     });
Exemplo n.º 3
0
        /// <inheritdoc/>
        public override ExpNode Execute(RowElimOperNode node)
        {
            // Ensure matrix.
            if (node.Child is TensorNode tensorNode && tensorNode.TensorType == TensorType.Matrix)
            {
                MatrixByRow matrix           = new MatrixByRow(tensorNode);
                int[]       leadingPositions = RefHelpers.GetLeadingColumns(matrix);

                // Put in row-echelon form
                for (int i = 0; i < matrix.Height; i++)
                {
                    int leftMostCol = RefHelpers.GetLeftMostColumn(leadingPositions, i);
                    matrix.SwapRows(i, leftMostCol);
                    Common.Swap(ref leadingPositions[i], ref leadingPositions[leftMostCol]);

                    if (leadingPositions[i] == -1)
                    {
                        continue;
                    }

                    matrix[i].MultiplyRow(QuickOpers.Reciprical(matrix[i][leadingPositions[i]]));
                    for (int j = i + 1; j < matrix.Height; j++)
                    {
                        matrix[j].AddRowToRow(matrix[i], QuickOpers.Negative(matrix[j][leadingPositions[i]]));
                        leadingPositions[j] = RefHelpers.GetLeadingColumn(matrix[j]);
                    }
                }

                if (node.EliminationMethod == RowElimMethod.GaussJordan)
                {
                    // Put in reduced row-echelon form
                    for (int i = matrix.Height - 1; i > 0; i--)
                    {
                        for (int j = i - 1; j >= 0; j--)
                        {
                            matrix[j].AddRowToRow(matrix[i], QuickOpers.Negative(matrix[j][leadingPositions[i]]));
                            leadingPositions[j] = RefHelpers.GetLeadingColumn(matrix[j]);
                        }
                    }
                }

                return(matrix.AsExpNode());
            }

            return(HandleError(new CannotReduceNonMatrix(this, node.Child)));
        }