Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a square <see cref="DiagonalMatrix"/> with all zero's except for ones on the diagonal.
        /// </summary>
        /// <param name="order">the size of the square matrix.</param>
        /// <returns>A diagonal identity matrix.</returns>
        /// <exception cref="ArgumentException">
        /// If <paramref name="order"/> is less than one.
        /// </exception>
        public static DiagonalMatrix Identity(int order)
        {
            var m = new DiagonalMatrix(order);

            for (var i = 0; i < order; i++)
            {
                m._data[i] = 1.0f;
            }

            return(m);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns the transpose of this matrix.
 /// </summary>        
 /// <returns>The transpose of this matrix.</returns>
 public override Matrix<float> Transpose()
 {
     var ret = new DiagonalMatrix(ColumnCount, RowCount);
     Buffer.BlockCopy(_data, 0, ret._data, 0, _data.Length * Constants.SizeOfFloat);
     return ret;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Subtracts another matrix from this matrix.
        /// </summary>
        /// <param name="other">The matrix to subtract.</param>
        /// <returns>The result of the subtraction.</returns>
        /// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
        public override Matrix<float> Subtract(Matrix<float> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other.RowCount != RowCount || other.ColumnCount != ColumnCount)
            {
                throw DimensionsDontMatch<ArgumentOutOfRangeException>(this, other, "other");
            }

            Matrix<float> result;
            if (other is DiagonalMatrix)
            {
                result = new DiagonalMatrix(RowCount, ColumnCount);
            }
            else
            {
                result = new DenseMatrix(RowCount, ColumnCount);
            }

            Subtract(other, result);
            return result;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a square <see cref="DiagonalMatrix"/> with all zero's except for ones on the diagonal.
        /// </summary>
        /// <param name="order">the size of the square matrix.</param>
        /// <returns>A diagonal identity matrix.</returns>
        /// <exception cref="ArgumentException">
        /// If <paramref name="order"/> is less than one.
        /// </exception>
        public static DiagonalMatrix Identity(int order)
        {
            var m = new DiagonalMatrix(order);
            for (var i = 0; i < order; i++)
            {
                m._data[i] = 1.0f;
            }

            return m;
        }
 public void MatrixFrom1DArrayIsReference()
 {
     var data = new float[] {1, 2, 3, 4, 5};
     var matrix = new DiagonalMatrix(5, 5, data);
     matrix[0, 0] = 10.0f;
     Assert.AreEqual(10.0f, data[0]);
 }
 public void CanCreateMatrixWithUniformValues()
 {
     var matrix = new DiagonalMatrix(10, 10, 10.0f);
     for (var i = 0; i < matrix.RowCount; i++)
     {
         Assert.AreEqual(matrix[i, i], 10.0f);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds another matrix to this matrix.
        /// </summary>
        /// <param name="other">The matrix to add to this matrix.</param>
        /// <returns>The result of the addition.</returns>
        /// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
        public override Matrix<float> Add(Matrix<float> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other.RowCount != RowCount || other.ColumnCount != ColumnCount)
            {
                throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions);
            }

            Matrix<float> result;
            if (other is DiagonalMatrix)
            {
                result = new DiagonalMatrix(RowCount, ColumnCount);
            }
            else
            {
                result = new DenseMatrix(RowCount, ColumnCount);
            }

            Add(other, result);
            return result;
        }
Ejemplo n.º 8
0
 private float[] single_correction(float[] coefs, float xdata, float ydata, float zdata)
 {
     float[] result = new float[3];
     Matrix B = new DiagonalMatrix(3, 3, 1);
     Matrix A = new DenseMatrix(3,3);
     A.At(0,0,coefs[0]);
     A.At(0,1,coefs[3]);
     A.At(0,2,coefs[4]);
     A.At(1,0,coefs[5]);
     A.At(1,1,coefs[1]);
     A.At(1,2,coefs[6]);
     A.At(2,0,coefs[7]);
     A.At(2,1,coefs[8]);
     A.At(2,2,coefs[2]);
     Matrix B1 = Kalman_class.Matrix_Minus(B, A);
     Matrix C = new DenseMatrix(3,1);
     C.At(0, 0, xdata);
     C.At(1, 0, ydata);
     C.At(2, 0, zdata);
     Matrix D = new DenseMatrix(3,1);
     D.At(0, 0, coefs[9]);
     D.At(1, 0, coefs[10]);
     D.At(2, 0, coefs[11]);
     Matrix res = new DenseMatrix(3,1);
     res = Kalman_class.Matrix_Mult(B1, Kalman_class.Matrix_Minus(C, D));
     result[0] = res.At(0, 0);
     result[1] = res.At(1, 0);
     result[2] = res.At(2, 0);
     return result;
 }