in

.NET Opensource

Community for opensource projects by Christoph Rüegg

Additional functions for the classes "matrix" and "vector"

Last post 05-21-2008 19:14 by Christoph Rüegg. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-16-2008 14:41

    • marX
    • Top 50 Contributor
      Male
    • Joined on 04-16-2008
    • Posts 2

    Additional functions for the classes "matrix" and "vector"

    Hi!

     At first I want to say, that I'm very glad to have found your libary. it is very helpful. - I'm missing some functions. Maybee they are allready implemented and I'm just not fit enough to find them. In case they are really missing, I want to suggest the following function to enhance the class "matrix".

     

            #region Functions added

            /// <summary>
            /// Finds the maximum value for each column. Similar to the Matlab-max-function.
            /// </summary>
            /// <returns>Vector containing the row-index of the maximum value in each column.</returns>
            public Vector ColumnMax()
            {
                Vector M = Vector.Zeros(this.ColumnCount);
                double helpValue = 0.0;

                for (int i = 0; i < this.ColumnCount; i++)
                {
                    //Set helpValue to the first value in the column.
                    helpValue = this[0, i];
                    for (int j = 0; j < this.RowCount; j++)
                    {
                        if (helpValue < this[j, i])
                        {
                            M[i] = j;
                        }
                    }
                }
                return M;
            }

            /// <summary>
            /// Finds the maximum value for each row.
            /// </summary>
            /// <returns>Vector containing the column-index of the maximum value in each row.</returns>
            public Vector RowMax()
            {
                Vector M = Vector.Zeros(this.RowCount);
                double helpValue = 0.0;

                for (int i = 0; i < this.RowCount; i++)
                {
                    //Set helpValue to the first value in the row.
                    helpValue = this[i, 0];
                    for (int j = 0; j < this.ColumnCount; j++)
                    {
                        if (helpValue < this[i, j])
                        {
                            M[i] = j;
                        }
                    }
                }
                return M;
            }

            /// <summary>
            /// Finds the minimum value for each column. Similar to the Matlab-max-function.
            /// </summary>
            /// <returns>Vector containing the row-index of the minimum value in each column.</returns>
            public Vector ColumnMin()
            {
                Vector M = Vector.Zeros(this.ColumnCount);
                double helpValue = 0.0;

                for (int i = 0; i < this.ColumnCount; i++)
                {
                    //Set helpValue to the first value in the column.
                    helpValue = this[0, i];
                    for (int j = 0; j < this.RowCount; j++)
                    {
                        if (helpValue > this[j, i])
                        {
                            M[i] = j;
                        }
                    }
                }
                return M;
            }

            /// <summary>
            /// Finds the minimum value for each row.
            /// </summary>
            /// <returns>Vector containing the column-index of the minimum value in each row.</returns>
            public Vector RowMin()
            {
                Vector M = Vector.Zeros(this.RowCount);
                double helpValue = 0.0;

                for (int i = 0; i < this.RowCount; i++)
                {
                    //Set helpValue to the first value in the row.
                    helpValue = this[i, 0];
                    for (int j = 0; j < this.ColumnCount; j++)
                    {
                        if (helpValue > this[i, j])
                        {
                            M[i] = j;
                        }
                    }
                }
                return M;
            }

            /// <summary>
            /// Calculates the sum of the columns.
            /// </summary>
            /// <returns>The sum of the considered column.</returns>
            public Vector ColumnSum()
            {
                Vector cSum = Vector.Zeros(this.ColumnCount);

                for (int i = 0; i < this.ColumnCount; i++)
                {
                    for (int j = 0; j < this.RowCount; j++)
                    {
                        cSum[i] = cSum[i] + this[j, i];
                    }
                }
                return cSum;
            }

            /// <summary>
            /// Calculates the sum of the rows.
            /// </summary>
            /// <returns>The sum of the considered row.</returns>
            public Vector RowSum()
            {
                Vector rSum = Vector.Zeros(this.RowCount);

                for (int i = 0; i < this.RowCount; i++)
                {
                    for (int j = 0; j < this.ColumnCount; j++)
                    {
                        rSum[i] = rSum[i] + this[i, j];
                    }
                }
                return rSum;
            }

            #endregion

     

    I think these functions are quite useful, because I know and use them in Matlab. Maybe you want to add them. If you trhink they are useful I thinik it would be nice, if the functions are also avaiable for the class "vector".

     

    Many thanks in forward! 

  • 05-21-2008 19:14 In reply to

    Re: Additional functions for the classes "matrix" and "vector"

    Thanks for the suggestions, I consider to add them (or something equivalent). I'll let you know (here). 

Page 1 of 1 (2 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems