コード例 #1
0
 public void PolynomialSet2zeroTest()
 {
     Polynomial P1 = new Polynomial(3, new double[] { 1, 1, 2, 1 });
     Assert.IsFalse(P1.isZero());
     Assert.IsFalse(P1.isZero(1));
     Assert.IsTrue(P1.isZero(2));
     P1.set2Zero();
     Assert.IsTrue(P1.isZero());
     P1 = new Polynomial(3, new double[] { 1, 1, 2, 1 });
     P1.set2Zero(2);
     Assert.IsTrue(P1.isZero(1));
 }
コード例 #2
0
ファイル: Matrix.cs プロジェクト: Marvin182/TaylorPLib
        /// <summary>
        /// Solves the equation<para/>
        /// <para/>
        ///     X U = B<para/>
        /// <para/>
        /// by back-substitution, where:<para/>
        /// <para/>
        ///     U : m-by-m upper triangular matrix, non-singular<para/>
        ///     X : m-by-n matrix<para/>
        ///     B : m-by-n matrix, overwritten with the solution on output.<para/>
        /// <para/>
        /// The X_ik are calculated making few modifications to the function 'utsolve' for UX=B.<para/>
        /// </summary>
        /// <param name="B">an object of type Matrix that is the independent term on input</param>
        public void utxsolve(Matrix B)
        {
            Polynomial sum = new Polynomial(_dimT);

            for( int k = 0; k < B._rows; k++ )
            {
                B._data[k, 0] /= _data[0, 0];
                for( int i = 1; i < B._cols; i++ )
                {
                    sum.set2Zero();
                    for( int j = 0; j < i; j++ )
                    {
                        sum += _data[j, i] * B._data[k, j];
                    }
                    B._data[k, i] = (B._data[k, i] - sum) / _data[i, i];
                }
            }
        }
コード例 #3
0
ファイル: Matrix.cs プロジェクト: Marvin182/TaylorPLib
        /// <summary>
        /// Solves the equation<para/>
        /// <para/>
        ///    U X = B<para/>
        /// <para/>
        /// by back-substitution, where:<para/>
        /// <para/>
        ///    U : m-by-m upper triangular matrix, non-singular<para/>
        ///    X : m-by-n matrix<para/>
        ///    B : m-by-n matrix, overwritten with the solution on output.<para/>
        ///<para/>
        /// The X_ik are calculated making few modifications to the algorithm 3.1.2, p.89 from <para/>
        /// Golub &amp; Van Loan's book:<para/>
        /// <para/>
        ///     x_ik = ( b_ik - sum_{j=i+1}^{m} u_ij * x_jk ) / u_ii     for k=1,...,n<para/>
        ///     <para/>
        /// </summary>
        /// <param name="B">an object of type Matrix that is the independent</param>
        /// <param name="X">an object of type Matrix that is the independent</param>
        /// <param name="piv"></param>
        public void utsolve(Matrix B, Matrix X, int[] piv)
        {
            Polynomial sum = new Polynomial(_dimT);

            for( int k = 0; k < B._cols; k++ )
            {
                X[_rows - 1, k] = B[piv[_rows - 1], k] / _data[piv[_rows - 1], _rows - 1];
                for( int i = _rows - 2; i > -1; i--)
                {
                    sum.set2Zero();
                    for( int j = i + 1; j < _rows; j++ )
                    {
                        sum += _data[piv[i], j] * X[j, k];
                    }
                    X[i, k] = (B[piv[i], k] - sum) / _data[piv[i], i];
                }
            }
        }
コード例 #4
0
ファイル: Matrix.cs プロジェクト: Marvin182/TaylorPLib
        /// <summary>
        /// Solves the equation<para/>
        /// <para/>
        ///     U x = b<para/>
        /// <para/>
        /// by back-substitution, where:<para/>
        /// <para/>
        ///     U : n-by-n upper triangular matrix, non-singular<para/>
        ///     x : n vector<para/>
        ///     B : n vector, overwritten with the solution on output.<para/>
        /// <para/>
        /// The x_i are calculated following the algorithm 3.1.2, p.89 from Golub &amp; Van Loan's book:<para/>
        /// <para/>
        ///     x_i = ( b_i - sum_{j=i+1}^{n} u_ij * x_j ) / u_ii<para/>
        /// </summary>
        /// <param name="b">an object of type Matrix that is the independent term on input</param>
        public void utsolve(Polynomial[] b)
        {
            Polynomial sum = new Polynomial(_dimT);

            b[_rows - 1] /= _data[_rows - 1,_rows - 1];
            for( int i = _rows - 2; i > -1; i-- )
            {
                sum.set2Zero();
                for( int j = i + 1; j < _rows; j++ )
                {
                    sum += _data[i,j] * b[j];
                }
                b[i] = (b[i] - sum) / _data[i,i];
            }
        }
コード例 #5
0
ファイル: Matrix.cs プロジェクト: Marvin182/TaylorPLib
        /// <summary>
        /// Solves the equation<para/>
        /// <para/>
        ///     U X = B<para/>
        /// <para/>
        /// by back-substitution, where:<para/>
        /// <para/>
        ///     U : m-by-m upper triangular matrix, non-singular<para/>
        ///     X : m-by-n matrix<para/>
        ///     B : m-by-n matrix, overwritten with the solution on output.<para/>
        ///     <para/>
        /// The X_ik are calculated making few modifications to the algorithm 3.1.2, p.89 from <para/>
        /// Golub &amp; Van Loan's book:<para/>
        /// <para/>
        ///     x_ik = ( b_ik - sum_{j=i+1}^{m} u_ij * x_jk ) / u_ii     for k=1,...,n<para/>
        /// <para/>
        /// </summary>
        /// <param name="B">an object of type Matrix that is the independent </param>
        public void utsolve(Matrix B)
        {
            if (!isSquare())
            {
                throw new MathException("U (=this) must be u squra matrix.");
            }

            if (B._rows != _rows)
            {
                throw new MathException(String.Format("The numebr rows in B ({0:d}) must match the number of rows in U (=this) ({1:d}).", B._rows, _rows));
            }

            Polynomial sum = new Polynomial(_dimT);

            Polynomial temp;
            for( int k = 0; k < B._cols; k++ )
            {
                temp = B[_rows - 1, k];
                B[_rows - 1, k] /= _data[_rows - 1,_rows - 1];
                temp = B[_rows - 1, k];
                for( int i = _rows - 2; i > -1; i-- )
                {
                    sum.set2Zero();
                    for( int j = i + 1; j < _rows; j++ )
                    {
                        sum += _data[i,j] * B._data[j,k];
                    }
                    B._data[i,k] = (B._data[i,k] - sum) / _data[i,i];
                }
            }
        }