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); ToeplizMatrix tMatrix1 = new ToeplizMatrix(n, n); tMatrix1.FillMatrixRandom(); Console.WriteLine(tMatrix1); ToeplizMatrix tMatrix2 = new ToeplizMatrix(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 ToeplizMatrix 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) { ToeplizMatrix tMat = otherMatrix as ToeplizMatrix; if (tMat == null) { return(base.Sum(otherMatrix)); } // TODO проверки ToeplizMatrix sumResult = new ToeplizMatrix(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); }