static void Main(string[] args) { uint n = 50; Matrix matrix1 = new Matrix(n, n); matrix1.FillMatrixRandom(); Console.WriteLine(matrix1); Matrix matrix2 = new Matrix(n, n); matrix2.FillMatrixRandom(); Console.WriteLine(matrix2); ToeplicMatrix tMatrix1 = new ToeplicMatrix(n, n); tMatrix1.FillMatrixRandom(); Console.WriteLine(tMatrix1); ToeplicMatrix tMatrix2 = new ToeplicMatrix(n, n); tMatrix2.FillMatrixRandom(); Console.WriteLine(tMatrix2); try { DateTime starttime = DateTime.Now; Console.WriteLine(matrix1.Sum(matrix2)); Console.WriteLine(DateTime.Now - starttime); starttime = DateTime.Now; Console.WriteLine(tMatrix1.Sum(tMatrix2)); Console.WriteLine(DateTime.Now - starttime); } catch (TwoMatrixOperationException exception) { Console.WriteLine(exception.Message); } catch (Exception exception) { Console.WriteLine(exception.Message); } finally { Console.Read(); } }
public static void FillMatrixRandom(this ToeplicMatrix matrix) { if (matrix == null) { return; } for (uint col = 0; col < matrix.ColCount; col++) { matrix[col, 0] = random.Next(0, 100); } for (uint row = 1; row < matrix.RowCount; row++) { matrix[0, row] = random.Next(0, 100); } }
public override Matrix Sum(Matrix otherMatrix) { ToeplicMatrix tMat = otherMatrix as ToeplicMatrix; if (tMat == null) { return(base.Sum(otherMatrix)); } // TODO проверки ToeplicMatrix sumResult = new ToeplicMatrix(ColCount, RowCount); for (int col = 0; col < ColCount; col++) { sumResult.firstRow[col] = firstRow[col] + tMat.firstRow[col]; } for (int row = 0; row < RowCount - 1; row++) { sumResult.firstCol[row] = firstCol[row] + tMat.firstCol[row]; } return(sumResult); }