private static void swapRows(MyMatrix <T> matrix, int row1, int row2) { if (row1 == row2) { return; } for (int i = 0; i < matrix.columnCount; i++) { T tmp = matrix[row1, i]; matrix[row1, i] = matrix[row2, i]; matrix[row2, i] = tmp; } return; }
private static MyMatrix <T> countVariables(MyMatrix <T> AB) { int n = AB.rowCount; MyMatrix <T> X = new MyMatrix <T>(AB.rowCount, 1); for (int i = n - 1; i >= 0; i--) { X[i, 0] = (dynamic)AB[i, n] / AB[i, i]; for (int k = i - 1; k >= 0; k--) { AB[k, n] -= (dynamic)AB[k, i] * X[i, 0]; } } return(X); }
private MyMatrix <T> resultByQueue(MyMatrix <T> vector, List <int> queue) { MyMatrix <T> tmp = new MyMatrix <T>(vector.rowCount, 1); for (int i = 0; i < vector.rowCount; i++) { for (int j = 0; j < vector.columnCount; j++) { tmp[i, j] = vector[i, j]; } } for (int i = 0; i < vector.rowCount; i++) { vector[queue[i], 0] = tmp[i, 0]; } return(vector); }
private static void swapColumns(MyMatrix <T> matrix, int column1, int column2, List <int> queue) { if (column1 == column2) { return; } int tmp = queue[column1]; queue[column1] = queue[column2]; queue[column2] = tmp; for (int i = 0; i < matrix.rowCount; i++) { T Tmp = matrix[i, column1]; matrix[i, column1] = matrix[i, column2]; matrix[i, column2] = Tmp; } return; }
public static MyMatrix <T> operator +(MyMatrix <T> a, MyMatrix <T> b) { if (a.rowCount != b.rowCount || a.columnCount != b.columnCount) { Console.WriteLine("Matrices sizes are incorrect for operation : a + b!"); return(null); } MyMatrix <T> c = new MyMatrix <T>(a.rowCount, a.columnCount); for (int i = 0; i < a.rowCount; i++) { for (int j = 0; j < a.columnCount; j++) { c.matrix[i, j] = (dynamic)a.matrix[i, j] + (dynamic)b.matrix[i, j]; } } return(c); }
public Fraction countDiffWithSameType(MyMatrix <T> matrix) { if (rowCount != matrix.rowCount) { throw new Exception("Wrong vector sizes!"); } if (columnCount != matrix.columnCount) { throw new Exception("Wrong Matrices sizes!"); } Fraction[,] thisTmp = new Fraction[rowCount, columnCount]; Fraction[,] matrixTmp = new Fraction[rowCount, columnCount]; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { if (typeof(T) == typeof(Fraction)) { thisTmp[i, j] = new Fraction((dynamic)this[i, j]); matrixTmp[i, j] = new Fraction((dynamic)matrix[i, j]); } else { thisTmp[i, j] = new Fraction(this[i, j].ToString()); matrixTmp[i, j] = new Fraction(matrix[i, j].ToString()); } } } Fraction sum = default(Fraction); for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { sum += Fraction.fracABS(thisTmp[i, j] - matrixTmp[i, j]); } } int count = rowCount * columnCount; Fraction div = new Fraction(count.ToString()); return(sum / div); }
public static MyMatrix <T> operator *(MyMatrix <T> a, MyMatrix <T> b) { if (a.columnCount != b.rowCount) { Console.WriteLine("Matrices sizes are incorrect for operation : a * b!"); return(null); } MyMatrix <T> c = new MyMatrix <T>(a.rowCount, b.columnCount); for (int i = 0; i < a.rowCount; i++) { for (int j = 0; j < b.columnCount; j++) { c.matrix[i, j] = default(T); for (int k = 0; k < b.rowCount; k++) { c.matrix[i, j] += (dynamic)a.matrix[i, k] * (dynamic)b.matrix[k, j]; } } } return(c); }
private static void findBiggestValue(MyMatrix <T> AB, int index, List <int> queue) { //size : n x (n+1) / 'AB' Matrix T max = AB[index, index]; int rowIndex = index; int columnIndex = index; for (int i = index; i < AB.rowCount; i++) { for (int j = index; j < AB.columnCount - 1; j++) //columnCount - 1 , to only look at nxn matrix { if ((dynamic)ABS(AB[i, j]) > max) { max = (dynamic)ABS(AB[i, j]); rowIndex = i; columnIndex = j; } } } swapRows(AB, index, rowIndex); swapColumns(AB, index, columnIndex, queue); }
public static MyMatrix <T> gauss(MyMatrix <T> AB, int version) { if (AB.rowCount != AB.columnCount - 1) { throw new Exception("Matrix N x (N+1) is required for Gaussian Eliminations!"); } int n = AB.rowCount; List <int> queue = new List <int>(); if (version == 1) //base { for (int i = 0; i < n; i++) { for (int k = i + 1; k < n; k++) { T c = (dynamic)((dynamic)default(T) - AB[k, i]) / AB[i, i]; for (int j = i; j < n + 1; j++) { if (i == j) { AB[k, j] = default(T); } else { AB[k, j] += c * (dynamic)AB[i, j]; } } } } } else if (version == 2) //partional { for (int i = 0; i < n; i++) { T max = ABS(AB[i, i]); int maxRow = i; for (int k = i + 1; k < n; k++) { if ((dynamic)ABS(AB[k, i]) > max) { max = ABS(AB[k, i]); maxRow = k; } } for (int k = i; k < n + 1; k++) { T tmp = (dynamic)AB[maxRow, k]; AB[maxRow, k] = AB[i, k]; AB[i, k] = tmp; } for (int k = i + 1; k < n; k++) { T c = ((dynamic)default(T) - AB[k, i]) / AB[i, i]; for (int j = i; j < n + 1; j++) { if (i == j) { AB[k, j] = default(T); } else { AB[k, j] += (dynamic)c * AB[i, j]; } } } } } else if (version == 3) //full { for (int i = 0; i < n; i++) { queue.Add(i); } for (int i = 0; i < n; i++) { findBiggestValue(AB, i, queue); for (int k = i + 1; k < n; k++) { T c = ((dynamic)default(T) - AB[k, i]) / AB[i, i]; for (int j = i; j < n + 1; j++) { if (i == j) { AB[k, j] = default(T); } else { AB[k, j] += (dynamic)c * AB[i, j]; } } } } } else { throw new Exception("Unknown Gauss elimination version! 1 - base, 2 - partial, 3 - full"); } MyMatrix <T> X = countVariables(AB); if (version == 3) { X.resultByQueue(X, queue); } return(X); }
public static void getInfo() { Console.WriteLine("GETTING INFORMATION :" + DateTime.Now.ToString()); int size = retrieveSize("size.txt"); double[,] sumOperationTimes = new double[3, 6]; double[,] sumOperationErrors = new double[3, 6]; double[] sumEigenOperationTimes = new double[5]; string[] avgEigenOperationErrors = new string[2]; avgEigenOperationErrors[0] = retrieveError(gaussErrDir + "\\" + "GaussPartialError.txt"); avgEigenOperationErrors[1] = retrieveError(gaussErrDir + "\\" + "GaussFullError.txt"); for (int c = 0; c < countOfVersions; c++) { double[,] operationTimes = new double[3, 6]; double[,] operationErrors = new double[3, 6]; double[] eigenOperationTimes = new double[5]; double[] eigenOperationErrors = new double[2]; string filePath = genDir + "\\" + valuesDir + (c + 1) + "\\"; Console.WriteLine("\n\n\nOpening directory : " + filePath); MyMatrix <double>[] matricesDouble = new MyMatrix <double> [countOfMatrices]; MyMatrix <double> vectorDouble = new MyMatrix <double>(convertToDouble(loadMatrix(filePath + "vector.txt", size, 1))); MyMatrix <float>[] matricesFloat = new MyMatrix <float> [countOfMatrices]; MyMatrix <float> vectorFloat = new MyMatrix <float>(convertToFloat(loadMatrix(filePath + "vector.txt", size, 1))); MyMatrix <Fraction>[] matricesFraction = new MyMatrix <Fraction> [countOfMatrices]; MyMatrix <Fraction> vectorFraction = new MyMatrix <Fraction>(convertToFraction(loadMatrix(filePath + "vector.txt", size, 1))); for (int i = 0; i < countOfMatrices; i++) { matricesDouble[i] = new MyMatrix <double>(convertToDouble(loadMatrix(filePath + "matrix" + (i + 1) + ".txt", size, size))); matricesFloat[i] = new MyMatrix <float>(convertToFloat(loadMatrix(filePath + "matrix" + (i + 1) + ".txt", size, size))); matricesFraction[i] = new MyMatrix <Fraction>(convertToFraction(loadMatrix(filePath + "matrix" + (i + 1) + ".txt", size, size))); } MyMatrix <Fraction> AXeigenFraction = new MyMatrix <Fraction>(convertToFraction(loadMatrix(filePath + "AX.txt", size, 1))); MyMatrix <Fraction> ABCXeigenFraction = new MyMatrix <Fraction>(convertToFraction(loadMatrix(filePath + "ABCX.txt", size, 1))); MyMatrix <Fraction> ABCeigenFraction = new MyMatrix <Fraction>(convertToFraction(loadMatrix(filePath + "ABC.txt", size, size))); eigenOperationTimes[0] = retrieveTime(filePath + "AX.txt"); eigenOperationTimes[1] = retrieveTime(filePath + "ABCX.txt"); eigenOperationTimes[2] = retrieveTime(filePath + "ABC.txt"); eigenOperationTimes[3] = retrieveTime(filePath + "partial.txt"); eigenOperationTimes[4] = retrieveTime(filePath + "full.txt"); Console.WriteLine("\nOPERATIONS OF MATRICES\n"); //-----------------------------------------------AX----------------------------------------------- Console.WriteLine("A * X\n"); //FLOAT Stopwatch stopWatch = new Stopwatch(); MyMatrix <float> AXfloat; stopWatch.Start(); AXfloat = matricesFloat[0] * vectorFloat; stopWatch.Stop(); operationTimes[0, 0] = stopWatch.ElapsedMilliseconds; Fraction AXfloatError = AXfloat.countDiffWithFrac(AXeigenFraction); operationErrors[0, 0] = AXfloatError.ToDouble(); Console.WriteLine("A * X FLOAT : "); Console.WriteLine("err : " + AXfloatError.ToDouble()); Console.WriteLine("time : " + operationTimes[0, 0] + " ms"); Console.WriteLine("----------------------------"); //DOUBLE MyMatrix <double> AXdouble; stopWatch.Restart(); AXdouble = matricesDouble[0] * vectorDouble; stopWatch.Stop(); operationTimes[1, 0] = stopWatch.ElapsedMilliseconds; Fraction AXdoubleError = AXdouble.countDiffWithFrac(AXeigenFraction); operationErrors[1, 0] = AXdoubleError.ToDouble(); Console.WriteLine("A * X DOUBLE : "); Console.WriteLine("err : " + AXdoubleError.ToDouble()); Console.WriteLine("time : " + operationTimes[1, 0] + " ms"); Console.WriteLine("----------------------------"); //FRACTION //MyMatrix<Fraction> AXfraction; //stopWatch.Restart(); //AXfraction = matricesFraction[0] * vectorFraction; //stopWatch.Stop(); //operationTimes[2, 0] = stopWatch.ElapsedMilliseconds; //Fraction AXfractionError = AXfraction.countDiffWithFrac(AXeigenFraction) //operationErrors[2, 0] = AXfractionError.ToDouble(); //Console.WriteLine("A * X FRACTION : "); //Console.WriteLine("err : " + AXfractionError.ToDouble()); //Console.WriteLine("time : " + operationTimes[2, 0] + " ms"); //Console.WriteLine("----------------------------"); //-----------------------------------------------(A+B+C) * X----------------------------------------------- Console.WriteLine("(A+B+C) * X\n"); //FLOAT MyMatrix <float> ABCXfloat; stopWatch.Restart(); ABCXfloat = (matricesFloat[0] + matricesFloat[1] + matricesFloat[2]) * vectorFloat; stopWatch.Stop(); operationTimes[0, 1] = stopWatch.ElapsedMilliseconds; Fraction ABCXfloatError = ABCXfloat.countDiffWithFrac(ABCXeigenFraction); operationErrors[0, 1] = ABCXfloatError.ToDouble(); Console.WriteLine("(A+B+C) * X FLOAT : "); Console.WriteLine("err : " + ABCXfloatError.ToDouble()); Console.WriteLine("time : " + operationTimes[0, 1] + " ms"); Console.WriteLine("----------------------------"); //DOUBLE MyMatrix <double> ABCXdouble; stopWatch.Restart(); ABCXdouble = (matricesDouble[0] + matricesDouble[1] + matricesDouble[2]) * vectorDouble; stopWatch.Stop(); operationTimes[1, 1] = stopWatch.ElapsedMilliseconds; Fraction ABCXdoubleError = ABCXdouble.countDiffWithFrac(ABCXeigenFraction); operationErrors[1, 1] = ABCXdoubleError.ToDouble(); Console.WriteLine("(A+B+C) * X DOUBLE : "); Console.WriteLine("err : " + ABCXdoubleError.ToDouble()); Console.WriteLine("time : " + operationTimes[1, 1] + " ms"); Console.WriteLine("----------------------------"); //FRACTION //MyMatrix<Fraction> ABCXfraction; //stopWatch.Restart(); //ABCXfraction = (matricesFraction[0] + matricesFraction[1] + matricesFraction[2]) * vectorFraction; //stopWatch.Stop(); //operationTimes[2, 1] = stopWatch.ElapsedMilliseconds; //Fraction ABCXfractionError = ABCXfraction.countDiffWithFrac(ABCXeigenFraction); //operationErrors[2, 1] = ABCXfractionError.ToDouble(); //Console.WriteLine("(A+B+C) * X FRACTION : "); //Console.WriteLine("err : " + ABCXfractionError.ToDouble()); //Console.WriteLine("time : " + operationTimes[2, 1] + " ms"); //Console.WriteLine("----------------------------"); //-----------------------------------------------A * B * C----------------------------------------------- Console.WriteLine("A * B * C\n"); //FLOAT MyMatrix <float> ABCfloat; stopWatch.Restart(); ABCfloat = matricesFloat[0] * matricesFloat[1] * matricesFloat[2]; stopWatch.Stop(); operationTimes[0, 2] = stopWatch.ElapsedMilliseconds; Fraction ABCfloatError = ABCfloat.countDiffWithFrac(ABCeigenFraction); operationErrors[0, 2] = ABCfloatError.ToDouble(); Console.WriteLine("A * B * C FLOAT : "); Console.WriteLine("err : " + ABCfloatError.ToDouble()); Console.WriteLine("time : " + operationTimes[0, 2] + " ms"); Console.WriteLine("----------------------------"); //DOUBLE MyMatrix <double> ABCdouble; stopWatch.Restart(); ABCdouble = matricesDouble[0] * matricesDouble[1] * matricesDouble[2]; stopWatch.Stop(); operationTimes[1, 2] = stopWatch.ElapsedMilliseconds; Fraction ABCdoubleError = ABCdouble.countDiffWithFrac(ABCeigenFraction); operationErrors[1, 2] = ABCdoubleError.ToDouble(); Console.WriteLine("A * B * C DOUBLE : "); Console.WriteLine("err : " + ABCdoubleError.ToDouble()); Console.WriteLine("time : " + operationTimes[1, 2] + " ms"); Console.WriteLine("----------------------------"); //FRACTION //MyMatrix<Fraction> ABCfraction; //stopWatch.Restart(); //ABCfraction = matricesFraction[0] * matricesFraction[1] * matricesFraction[2]; //stopWatch.Stop(); //operationTimes[2, 2] = stopWatch.ElapsedMilliseconds; //Fraction ABCfractionError = ABCfraction.countDiffWithFrac(ABCeigenFraction); //operationErrors[2, 2] = ABCfractionError.ToDouble(); //Console.WriteLine("A * B * C FRACTION : "); //Console.WriteLine("err : " + ABCfractionError.ToDouble()); //Console.WriteLine("time : " + operationTimes[2, 2] + " ms"); //Console.WriteLine("----------------------------"); //END OF MATRICES OPERATIONS... MyMatrix <float> somewhatVectorFloat; MyMatrix <double> somewhatVectorDouble; MyMatrix <Fraction> somewhatVectorFraction; Console.WriteLine("\nGAUSS ELIMINATIONS\n"); //-----------------------------------------------GAUSS BASE----------------------------------------------- Console.WriteLine("GAUSS BASE\n"); //FLOAT MyMatrix <float> gaussBaseResultFloat; MyMatrix <float> ABForGaussBaseFloat = MyMatrix <float> .matrixJoinVector(matricesFloat[0], vectorFloat); stopWatch.Restart(); gaussBaseResultFloat = MyMatrix <float> .gauss(ABForGaussBaseFloat, 1); stopWatch.Stop(); operationTimes[0, 3] = stopWatch.ElapsedMilliseconds; somewhatVectorFloat = matricesFloat[0] * gaussBaseResultFloat; Fraction gaussBaseFloatError = somewhatVectorFloat.countDiffWithSameType(vectorFloat); operationErrors[0, 3] = gaussBaseFloatError.ToDouble(); Console.WriteLine("GAUSS BASE FLOAT : "); Console.WriteLine("err : " + gaussBaseFloatError.ToDouble()); Console.WriteLine("time : " + operationTimes[0, 3] + " ms"); Console.WriteLine("----------------------------"); //DOUBLE MyMatrix <double> gaussBaseResultDouble; MyMatrix <double> ABForGaussBaseDouble = MyMatrix <double> .matrixJoinVector(matricesDouble[0], vectorDouble); stopWatch.Restart(); gaussBaseResultDouble = MyMatrix <double> .gauss(ABForGaussBaseDouble, 1); stopWatch.Stop(); operationTimes[1, 3] = stopWatch.ElapsedMilliseconds; somewhatVectorDouble = matricesDouble[0] * gaussBaseResultDouble; Fraction gaussBaseDoubleError = somewhatVectorDouble.countDiffWithSameType(vectorDouble); operationErrors[1, 3] = gaussBaseDoubleError.ToDouble(); Console.WriteLine("GAUSS BASE DOUBLE : "); Console.WriteLine("err : " + gaussBaseDoubleError.ToDouble()); Console.WriteLine("time : " + operationTimes[1, 3] + " ms"); Console.WriteLine("----------------------------"); //FRACTION //MyMatrix<Fraction> gaussBaseResultFraction; //MyMatrix<Fraction> ABForGaussBaseFraction = MyMatrix<Fraction>.matrixJoinVector(matricesFraction[0], vectorFraction); //stopWatch.Restart(); //gaussBaseResultFraction = MyMatrix<Fraction>.gauss(ABForGaussBaseFraction, 1); //stopWatch.Stop(); //operationTimes[2, 3] = stopWatch.ElapsedMilliseconds; //somewhatVectorFraction = matricesFraction[0] * gaussBaseResultFraction; //Fraction gaussBaseFractionError = somewhatVectorFraction.countDiffWithSameType(vectorFraction); //operationErrors[2, 3] = gaussBaseFractionError.ToDouble(); //Console.WriteLine("GAUSS BASE FRACTION : "); //Console.WriteLine("err : " + gaussBaseFractionError.ToDouble()); //Console.WriteLine("time : " + operationTimes[2, 3] + " ms"); //Console.WriteLine("----------------------------"); //-----------------------------------------------GAUSS PARTIAL----------------------------------------------- Console.WriteLine("GAUSS PARTIAL\n"); //FLOAT MyMatrix <float> gaussPartialResultFloat; MyMatrix <float> ABForGaussPartialFloat = MyMatrix <float> .matrixJoinVector(matricesFloat[0], vectorFloat); stopWatch.Restart(); gaussPartialResultFloat = MyMatrix <float> .gauss(ABForGaussPartialFloat, 2); stopWatch.Stop(); operationTimes[0, 4] = stopWatch.ElapsedMilliseconds; somewhatVectorFloat = matricesFloat[0] * gaussPartialResultFloat; Fraction gaussPartialFloatError = somewhatVectorFloat.countDiffWithSameType(vectorFloat); operationErrors[0, 4] = gaussPartialFloatError.ToDouble(); Console.WriteLine("GAUSS PARTIAL FLOAT : "); Console.WriteLine("err : " + gaussPartialFloatError.ToDouble()); Console.WriteLine("time : " + operationTimes[0, 4] + " ms"); Console.WriteLine("----------------------------"); //DOUBLE MyMatrix <double> gaussPartialResultDouble; MyMatrix <double> ABForGaussPartialDouble = MyMatrix <double> .matrixJoinVector(matricesDouble[0], vectorDouble); stopWatch.Restart(); gaussPartialResultDouble = MyMatrix <double> .gauss(ABForGaussPartialDouble, 2); stopWatch.Stop(); operationTimes[1, 4] = stopWatch.ElapsedMilliseconds; somewhatVectorDouble = matricesDouble[0] * gaussPartialResultDouble; Fraction gaussPartialDoubleError = somewhatVectorDouble.countDiffWithSameType(vectorDouble); operationErrors[1, 4] = gaussPartialDoubleError.ToDouble(); Console.WriteLine("GAUSS PARTIAL DOUBLE : "); Console.WriteLine("err : " + gaussPartialDoubleError.ToDouble()); Console.WriteLine("time : " + operationTimes[1, 4] + " ms"); Console.WriteLine("----------------------------"); //FRACTION //MyMatrix<Fraction> gaussPartialResultFraction; //MyMatrix<Fraction> ABForGaussPartialFraction = MyMatrix<Fraction>.matrixJoinVector(matricesFraction[0], vectorFraction); //stopWatch.Restart(); //gaussPartialResultFraction = MyMatrix<Fraction>.gauss(ABForGaussPartialFraction, 2); //stopWatch.Stop(); //operationTimes[2, 4] = stopWatch.ElapsedMilliseconds; //somewhatVectorFraction = matricesFraction[0] * gaussPartialResultFraction; //Fraction gaussPartialFractionError = somewhatVectorFraction.countDiffWithSameType(vectorFraction); //operationErrors[2, 4] = gaussPartialFractionError.ToDouble(); //Console.WriteLine("GAUSS PARTIAL FRACTION : "); //Console.WriteLine("err : " + gaussPartialFractionError.ToDouble()); //Console.WriteLine("time : " + operationTimes[2, 4] + " ms"); //Console.WriteLine("----------------------------"); //-----------------------------------------------GAUSS FULL----------------------------------------------- Console.WriteLine("GAUSS FULL\n"); //FLOAT MyMatrix <float> gaussFullResultFloat; MyMatrix <float> ABForGaussFullFloat = MyMatrix <float> .matrixJoinVector(matricesFloat[0], vectorFloat); stopWatch.Restart(); gaussFullResultFloat = MyMatrix <float> .gauss(ABForGaussFullFloat, 3); stopWatch.Stop(); operationTimes[0, 5] = stopWatch.ElapsedMilliseconds; somewhatVectorFloat = matricesFloat[0] * gaussFullResultFloat; Fraction gaussFullFloatError = somewhatVectorFloat.countDiffWithSameType(vectorFloat); operationErrors[0, 5] = gaussFullFloatError.ToDouble(); Console.WriteLine("GAUSS FULL FLOAT : "); Console.WriteLine("err : " + gaussFullFloatError.ToDouble()); Console.WriteLine("time : " + operationTimes[0, 5] + " ms"); Console.WriteLine("----------------------------"); //DOUBLE MyMatrix <double> gaussFullResultDouble; MyMatrix <double> ABForGaussFullDouble = MyMatrix <double> .matrixJoinVector(matricesDouble[0], vectorDouble); stopWatch.Restart(); gaussFullResultDouble = MyMatrix <double> .gauss(ABForGaussFullDouble, 3); stopWatch.Stop(); operationTimes[1, 5] = stopWatch.ElapsedMilliseconds; somewhatVectorDouble = matricesDouble[0] * gaussFullResultDouble; Fraction gaussFullDoubleError = somewhatVectorDouble.countDiffWithSameType(vectorDouble); operationErrors[1, 5] = gaussFullDoubleError.ToDouble(); Console.WriteLine("GAUSS FULL DOUBLE : "); Console.WriteLine("err : " + gaussFullDoubleError.ToDouble()); Console.WriteLine("time : " + operationTimes[1, 5] + " ms"); Console.WriteLine("----------------------------"); //FRACTION //MyMatrix<Fraction> gaussFullResultFraction; //MyMatrix<Fraction> ABForGaussFullFraction = MyMatrix<Fraction>.matrixJoinVector(matricesFraction[0], vectorFraction); //stopWatch.Restart(); //gaussFullResultFraction = MyMatrix<Fraction>.gauss(ABForGaussFullFraction,3); //stopWatch.Stop(); //operationTimes[2, 5] = stopWatch.ElapsedMilliseconds; //somewhatVectorFraction = matricesFraction[0] * gaussFullResultFraction; //Fraction gaussFullFractionError = somewhatVectorFraction.countDiffWithSameType(vectorFraction); //operationErrors[2, 5] = gaussFullFractionError.ToDouble(); //Console.WriteLine("GAUSS FULL FRACTION : "); //Console.WriteLine("err : " + gaussFullFractionError.ToDouble()); //Console.WriteLine("time : " + operationTimes[2, 5] + " ms"); //Console.WriteLine("----------------------------"); //-----------------------------------------------GAUSS EIGEN----------------------------------------------- //EIGEN PARTIAL Console.WriteLine("GAUSS PARTIAL EIGEN : "); Console.WriteLine("avg err : " + avgEigenOperationErrors[0]); Console.WriteLine("time : " + eigenOperationTimes[3] + " sec"); Console.WriteLine("----------------------------"); //EIGEN FULL Console.WriteLine("GAUSS FULL EIGEN : "); Console.WriteLine("avg err : " + avgEigenOperationErrors[1]); Console.WriteLine("time : " + eigenOperationTimes[4] + " sec"); Console.WriteLine("----------------------------"); for (int i = 0; i < 3; i++) { for (int j = 0; j < 6; j++) { sumOperationTimes[i, j] += operationTimes[i, j]; sumOperationErrors[i, j] += operationErrors[i, j]; } } for (int i = 0; i < 5; i++) { sumEigenOperationTimes[i] += eigenOperationTimes[i]; } } Console.WriteLine("\n\nSUCCESS : COUNTING AVERAGE VALUES FOR ERRORS AND TIMES FOR " + countOfVersions + " VERSIONS FOR SIZE " + size); double[,] avgOperationTimes = new double[3, 6]; double[,] avgOperationErrors = new double[3, 6]; double[] avgEigenOperationTimes = new double[5]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 6; j++) { avgOperationTimes[i, j] = sumOperationTimes[i, j] / countOfVersions; avgOperationErrors[i, j] = sumOperationErrors[i, j] / countOfVersions; } } for (int i = 0; i < 5; i++) { avgEigenOperationTimes[i] = sumEigenOperationTimes[i] / countOfVersions; } string opAX = operationsOnMatrixInfo(size, 0, 0, avgOperationErrors, avgOperationTimes, avgEigenOperationTimes); string opABCX = operationsOnMatrixInfo(size, 1, 1, avgOperationErrors, avgOperationTimes, avgEigenOperationTimes); string opABC = operationsOnMatrixInfo(size, 2, 2, avgOperationErrors, avgOperationTimes, avgEigenOperationTimes); string opGaussBase = operationsOnGaussBaseInfo(size, 3, avgOperationErrors, avgOperationTimes); string opGaussPartial = operationsOnGaussFullPartialInfo(size, 4, 0, 3, avgOperationErrors, avgOperationTimes, avgEigenOperationTimes, avgEigenOperationErrors); string opGaussFull = operationsOnGaussFullPartialInfo(size, 5, 1, 4, avgOperationErrors, avgOperationTimes, avgEigenOperationTimes, avgEigenOperationErrors); if (!Directory.Exists("Results" + size)) { Console.WriteLine("Creating directory : Results" + size); DirectoryInfo di = Directory.CreateDirectory("Results" + size); } File.WriteAllText("Results" + size + "\\" + "AXresult" + size + ".txt", opAX); File.WriteAllText("Results" + size + "\\" + "ABCXresult" + size + ".txt", opABCX); File.WriteAllText("Results" + size + "\\" + "ABCresult" + size + ".txt", opABC); File.WriteAllText("Results" + size + "\\" + "GaussBaseResult" + size + ".txt", opGaussBase); File.WriteAllText("Results" + size + "\\" + "GaussPartialResult" + size + ".txt", opGaussPartial); File.WriteAllText("Results" + size + "\\" + "GaussFullResult" + size + ".txt", opGaussFull); }