public float[][] CheckH2(int numberOfElements) { float[][] resultsComp = new float[3][]; float[][] matrix = DataSource.GetMatrixData <float>(numberOfElements); float[][] matrixCopy = DataSource.GetMatrixData <float>(numberOfElements); float resNormalType = 0; var algorithmFloat = new AlgorithmGen <float>(numberOfElements); var vectorFloatNormal = algorithmFloat.GaussElimination(matrix, 0, EnumsContainer.GaussType.Normal); resultsComp[0] = algorithmFloat.CalculateError(matrixCopy, vectorFloatNormal); matrix = DataSource.GetMatrixData <float>(numberOfElements); var vectorFloatPartial = algorithmFloat.GaussElimination(matrix, 0, EnumsContainer.GaussType.PartialPivot); resultsComp[1] = algorithmFloat.CalculateError(matrixCopy, vectorFloatPartial); int[] indexArray = new int[numberOfElements]; for (int i = 0; i < numberOfElements; i++) { indexArray[i] = i; } matrix = DataSource.GetMatrixData <float>(numberOfElements); var vectorFloatFull = algorithmFloat.GaussElimination(matrix, 0, EnumsContainer.GaussType.FullPivot, indexArray); resultsComp[2] = algorithmFloat.CalculateError(matrixCopy, vectorFloatFull); return(resultsComp); }
public void CheckH3(int numberOfElements, int numberOfTests) { #region Fractiontype long[] algTimes = new long[3]; AlgorithmGen <FractionType> algorithmFracType = new AlgorithmGen <FractionType>(numberOfElements); AlgorithmGen <float> algorithm = new AlgorithmGen <float>(numberOfElements); for (int pf = 0; pf < numberOfTests; pf++) { FractionType[][] matrixFracCopyToCompare = DataSource.GetMatrixData <FractionType>(numberOfElements); FractionType[][] MatrixFracType = DataSource.GetMatrixData <FractionType>(numberOfElements); FractionType[][] Matrix2FracType = DataSource.GetMatrixData <FractionType>(numberOfElements);; FractionType[][] Matrix3FracType = DataSource.GetMatrixData <FractionType>(numberOfElements);; float[][] matrixCopy = DataSource.GetMatrixData <float>(numberOfElements); #region GaussTypeNormal FractionType res1 = new FractionType(); //get alg time var vectorResultFracType = algorithmFracType.GaussElimination(MatrixFracType, new FractionType(), EnumsContainer.GaussType.Normal); var varctorResultFracTypeToFloat = new float[numberOfElements]; if (vectorResultFracType != null) { for (int m = 0; m < vectorResultFracType.Length; m++) { while (vectorResultFracType[m].Numerator.ToString().Length > 9 || vectorResultFracType[m].Denominator.ToString().Length > 9) { vectorResultFracType[m].Numerator /= 10; vectorResultFracType[m].Denominator /= 10; } varctorResultFracTypeToFloat[m] = ((float)vectorResultFracType[m].Numerator / (float)vectorResultFracType[m].Denominator); } var rtnFracTypeError = algorithmFracType.CalculateError(matrixFracCopyToCompare, vectorResultFracType); algorithmFracType.PrintResult(rtnFracTypeError); } #endregion #region GaussPartialPivot var vectorResult2 = algorithmFracType.GaussElimination(Matrix2FracType, new FractionType(), EnumsContainer.GaussType.PartialPivot); var verctorResultFracTypePartialPivot = new float[numberOfElements]; if (vectorResult2 != null) { for (int m = 0; m < vectorResult2.Length; m++) { while (vectorResult2[m].Numerator.ToString().Length > 9 || vectorResult2[m].Denominator.ToString().Length > 9) { vectorResult2[m].Numerator /= 10; vectorResult2[m].Denominator /= 10; } verctorResultFracTypePartialPivot[m] = (float)((float)vectorResult2[m].Numerator / (float)vectorResult2[m].Denominator); } var rtnFracTypeError = algorithmFracType.CalculateError(matrixFracCopyToCompare, vectorResultFracType); algorithmFracType.PrintResult(rtnFracTypeError); } #endregion #region GaussTypeFullPivot int[] indexArray = new int[numberOfElements]; for (int i = 0; i < numberOfElements; i++) { indexArray[i] = i; } var vectorResult3 = algorithmFracType.GaussElimination(Matrix3FracType, new FractionType(), EnumsContainer.GaussType.FullPivot, indexArray); var verctorResultFracTypeFullpivot = new float[numberOfElements]; if (vectorResult3 != null) { for (int m = 0; m < vectorResult3.Length; m++) { while (vectorResult3[m].Numerator.ToString().Length > 9 || vectorResult3[m].Denominator.ToString().Length > 9) { vectorResult3[m].Numerator /= 10; vectorResult3[m].Denominator /= 10; } verctorResultFracTypeFullpivot[m] = ((float)vectorResult3[m].Numerator / (float)vectorResult3[m].Denominator); } var rtnFracTypeError = algorithmFracType.CalculateError(matrixFracCopyToCompare, vectorResultFracType); algorithmFracType.PrintResult(rtnFracTypeError); } #endregion } #endregion }
public void CheckQ1 <T>(int numberOfElements) where T : struct { List <ResultSet <T> > resultsSetdouble = new List <ResultSet <T> >(); for (int matrixSize = 10; matrixSize < numberOfElements; matrixSize += 10) { T normalRes = default(T); T partialRes = default(T); var dataSource = new DataSource(matrixSize); var algorithm = new AlgorithmGen <T>(matrixSize); T[][] Matrix = dataSource.GetMatrixData <T>(matrixSize); T[][] MatrixCopy = dataSource.GetMatrixData <T>(matrixSize); T[][] Matrix2 = dataSource.GetMatrixData <T>(matrixSize); double[][] Matrix3 = new double[matrixSize][]; for (var i = 0; i < Matrix.Length; i++) { Matrix3[i] = new double[Matrix[i].Length]; Array.Copy(Matrix[i], Matrix3[i], Matrix[i].Length); } #region GaussTypeNormal dynamic resNormalType = 0; var vectorResult = algorithm.GaussElimination(Matrix, resNormalType, EnumsContainer.GaussType.Normal); if (vectorResult != null) { var rtn = algorithm.CalculateError(MatrixCopy, vectorResult); foreach (var variable in rtn) { normalRes += Math.Abs(variable); } normalRes /= rtn.Length; } #endregion #region GaussPartialPivot resNormalType = 0; var vectorResultPartial = algorithm.GaussElimination(Matrix2, resNormalType, EnumsContainer.GaussType.PartialPivot); if (vectorResultPartial != null) { var rtn = algorithm.CalculateError(MatrixCopy, vectorResultPartial); foreach (var variable in rtn) { partialRes = Add(partialRes, Abs(variable)); } dynamic rtnLength = rtn.Length; partialRes = Divide <T>(partialRes, rtnLength); } resultsSetdouble.Add(new ResultSet <T> { ResultNormal = normalRes, ResultPartial = partialRes }); #endregion /* #region GaussTypeFullPivot * int[] indexArray = new int[matrixSize]; * for (int i = 0; i < matrixSize; i++) * { * indexArray[i] = i; * } * * double res3 = 0; * var vectorResult3 = algorithm.GaussElimination(Matrix3, 0, EnumsContainer.GaussType.FullPivot, indexArray); * if (vectorResult3 != null) * { * algorithm.PrintResult(vectorResult3); * var rtn = algorithm.CalculateError(MatrixCopy, vectorResult3); * Console.WriteLine(); * algorithm.PrintResult(vectorResult3); * * foreach (var variable in rtn) * { * res3 += variable; * } * Console.WriteLine("Result:" + Math.Abs(res3)); * } * #endregion */ } WriteResultsToExcelFile(resultsSetdouble); Console.WriteLine("done"); }