/********************************************** * private constructor * provides input of a matrix x, and row index and colIndex * output is a matrix derived from x, which does not include * elements from row and col provided * private becasue it is not for public consumption but only * used by Determinant ***********************************************/ private Matrix(Matrix x, int row, int coll) { int counteri = 0, counterj = 0; _matrixContent = new Vector[x._matrixContent.Length - 1]; for (var i = 0; i < x._matrixContent.Length; i++) { if (i != row) _matrixContent[counteri] = new Vector { Length = x._matrixContent[0].Length - 1 }; var bIncrementcounter = false; for (var j = 0; j < x._matrixContent[0].Length; j++) { if ((i == row) || (j == coll)) continue; _matrixContent[counteri][counterj++] = x._matrixContent[i][j]; bIncrementcounter = true; } if (!bIncrementcounter) continue; counteri++; counterj = 0; } }
/// <summary> /// Contructor for defining the "rows" and "colls" /// </summary> /// <param name="rows"></param> /// <param name="colls"></param> public Matrix(int rows, int colls) { _matrixContent = new Vector[rows]; for (var i = 0; i < rows; i++) { _matrixContent[i] = new Vector { Length = colls }; } }
//other functions private static Vector Operation(Vector vec1, Vector vec2, Func<double,double,double> operation) { Vector maxLengthVector; Vector minLengthVector; if (vec1.Length <= vec2.Length) { minLengthVector = vec1; maxLengthVector = vec2; } else { minLengthVector = vec2; maxLengthVector = vec1; } var result = new Vector { Length = maxLengthVector.Length }; for (var i = 0; i < maxLengthVector.Length; i++) { if (i < minLengthVector.Length) { result[i] = operation(vec1[i], vec2[i]); } else { result[i] = maxLengthVector[i]; } } return result; }
private static bool ComparsionOperation(Vector vec1, Vector vec2, Func<double, double, bool> comparsionOperation) { Vector maxLengthVector; Vector minLengthVector; if (vec1.Length <= vec2.Length) { minLengthVector = vec1; maxLengthVector = vec2; } else { minLengthVector = vec2; maxLengthVector = vec1; } if (comparsionOperation(maxLengthVector.Length, minLengthVector.Length)) { for (var i = 0; i < maxLengthVector.Length; i++) { if (i >= minLengthVector.Length) continue; if (!comparsionOperation(vec1[i], vec2[i])) return false; } } else { return false; } return true; }