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!