public void ThirdEquationTest() { Matrix variableCoefficients = new Matrix(new float[, ] { { 8, 5, 3 }, { -2, 8, 1 }, { 1, 3, -10 } }); Matrix freeCoefficients = new Matrix(new float[, ] { { 30 }, { 15 }, { 42 } }); Matrix expectedResult = new Matrix(new float[, ] { { 3f }, { 3f }, { -3f } }); float epsilon = 0.0001f; Matrix result = JacobiMethod.Solve(variableCoefficients, freeCoefficients, epsilon); Assert.True(expectedResult.NearEquals(result), "Matrices are not equal:\nExpected:{0}\nResult:{1}", expectedResult.ToString(), result.ToString()); }
public void SecondEquationTest() { Matrix variableCoefficients = new Matrix(new float[, ] { { 2, -1, -1 }, { 1, 3, -2 }, { 1, 2, 3 } }); Matrix freeCoefficients = new Matrix(new float[, ] { { 5 }, { 7 }, { 10 } }); Matrix expectedResult = new Matrix(new float[, ] { { 61f / 16f }, { 27f / 16f }, { 15f / 16f } }); float epsilon = 0.0001f; Matrix result = JacobiMethod.Solve(variableCoefficients, freeCoefficients, epsilon); Assert.True(expectedResult.NearEquals(result), "Matrices are not equal:\nExpected:{0}\nResult:{1}", expectedResult.ToString(), result.ToString()); }
public void SolveTest() { var coef = new double[3, 3] { { 5, 2, 3 }, { 2, 6, 1 }, { 5, 2, 7 } }; var cnst = new double[] { 4, 3, 2 }; var e_solution = new double[] { 1, 0.25, -0.5 }; JacobiMethod jacobiMethod = new JacobiMethod(coef, cnst); jacobiMethod.Error = 1E-20; jacobiMethod.CheckInterval = 10; jacobiMethod.Solve(); var solution = jacobiMethod.Solution; var accuracy = true; for (int i = 0; i < solution.Length; i++) { accuracy &= solution[i] == e_solution[i]; } Console.Write("Number of Iteration : "); Console.WriteLine(jacobiMethod.NoIteration); Console.WriteLine(solution[0]); Console.WriteLine(solution[1]); Console.WriteLine(solution[2]); Console.Write("Final Residue : "); Console.WriteLine(jacobiMethod.FinalResidue); Assert.IsTrue(accuracy); }
public MethodsController(IHostingEnvironment environment, Options options) { _hostingEnvironment = environment; _options = options; _jacobiMethodCPP = new JacobiMethod(); _jacobiMethodCPP.Implementation = "C++ is a high-level, general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language."; _multiplicationASM = new MatrixMultiplication(); _multiplicationASM.Implementation = "In computer programming, assembly language(or assembler language), often abbreviated asm, is any low - level programming language in which there is a very strong correspondence between the instructions in the language and the architecture's machine code instructions."; }
public MethodsController(IHostingEnvironment environment, Options options) { _hostingEnvironment = environment; _options = options; _jacobiMethodCPP = new JacobiMethod(); _jacobiMethodCPP.Implementation = "C++ is a high-level, general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language."; _multiplicationCPP = new Models.MatrixMultiplication(); _multiplicationCPP.Implementation = "This method was written on C++ which is a high - level, general - purpose programming language. The first optimization is to re-order the loops to enforce local access in all of the matrices. The standard mapping was then used from a two-dimensional array onto a one-dimensional space. This makes explicit the fact that subscripting in a two-dimensional array requires integer multiplication as well as addition. Replacing subscripting with explicit pointer access allows the elimination of these multiplications."; }
public IActionResult FormJacobiMethod(JacobiMethod jacobiMethod) { if (jacobiMethod.VectorB != null && jacobiMethod.MatrixA != null && jacobiMethod.VectorX != null) { JacobiMethodCPlusPlus jacobiMethodCPP = new JacobiMethodCPlusPlus(); if (jacobiMethodCPP.method(jacobiMethod.MatrixA, jacobiMethod.VectorB, jacobiMethod.VectorX, jacobiMethod.Eps)) { _jacobiMethodCPP.Result = jacobiMethodCPP.getVectorX(); } } return(View(_jacobiMethodCPP)); }
public async Task <IActionResult> FileJacobiDownload(JacobiMethod jacobiMethod, IFormFileCollection inputFiles) { uint id = _options.FileId; lock (_options) _options.FileId++; List <string> markers = new List <string> { "A", "b", "x" }; int i = 0; string fileResult = _hostingEnvironment.WebRootPath + "\\output_files\\"; string files = Path.Combine(_hostingEnvironment.WebRootPath, "input_files"); foreach (var file in inputFiles) { if (file != null) { string filePath = Path.Combine(files, id.ToString() + markers[i] + ".txt"); await using FileStream stream = System.IO.File.Create(filePath); await file.CopyToAsync(stream); stream.Close(); } i++; } try { JacobiMethodCPlusPlus jacobiMethodCPlusPlus = new JacobiMethodCPlusPlus(); if (jacobiMethodCPlusPlus.method(id, jacobiMethod.Eps)) { fileResult += id.ToString() + ".txt"; } else { fileResult += "empty.txt"; } } catch (Exception) { } Stream newStream = new FileStream(fileResult, FileMode.Open); return(File(newStream, "text/plain")); }
private async void SolveAsync() { /* * foreach (string Method in Types) * { * ILogger Logger = new FakeLog(); * LoggingSolver loggingSolver = Spawn(Method, Logger); * IVector result = await RunAsync(loggingSolver, matrix, x0, b); * } */ //Необходима фабрика решателей, жду слияния главной ветки и ветки решателей //временная мера для запуска программы for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++) { LoggingSolver loggingSolver; IMethod Method = new JacobiMethod(); ILogger Logger = new FakeLog(); loggingSolver = new LoggingSolver(Method, Logger); IVector result = await RunAsync(loggingSolver, currentSLAE.matrix, currentSLAE.x0, currentSLAE.b); } }
public IActionResult FormJacobiMethod(JacobiMethod jacobiMethod) { if (jacobiMethod.VectorB != null && jacobiMethod.MatrixA != null && jacobiMethod.VectorX != null) { try { JacobiMethodCPlusPlus jacobiMethodCPP = new JacobiMethodCPlusPlus(); if (jacobiMethodCPP.method(jacobiMethod.MatrixA, jacobiMethod.VectorB, jacobiMethod.VectorX, jacobiMethod.Eps)) { _jacobiMethodCPP.Result = jacobiMethodCPP.getVectorX(); } else { _jacobiMethodCPP.Result = "It is not strictly diagonally dominant system of linear equations."; } } catch (Exception) { } } return(View(_jacobiMethodCPP)); }
static void Test(int iterations, Matrix variableCoefficients, Matrix freeCoefficients) { float epsilon = 0.0001f; float relaxationWeight = 0.8f; var stopwatch = new Stopwatch(); Console.Write("######################################################\nSelect the algorithm:\n1.Gauss\n2.Jacobi\n3.Gauss-Seidel\n4.Relaxation\nEnter the choice:"); int algorithm = Convert.ToInt32(Console.ReadLine()); switch (algorithm) { case 1: { stopwatch.Start(); for (int i = 0; i < iterations; i++) { var result = GaussMethod.Solve(Matrix.Clone(variableCoefficients), Matrix.Clone(freeCoefficients)); } stopwatch.Stop(); Console.WriteLine("Total elapsed time: " + stopwatch.Elapsed + "\n######################################################"); break; } case 2: { stopwatch.Start(); for (int i = 0; i < iterations; i++) { var result = JacobiMethod.Solve(Matrix.Clone(variableCoefficients), Matrix.Clone(freeCoefficients), epsilon); } stopwatch.Stop(); Console.WriteLine("Total elapsed time: " + stopwatch.Elapsed); break; } case 3: { stopwatch.Start(); for (int i = 0; i < iterations; i++) { var result = GaussZeidelMethod.Solve(Matrix.Clone(variableCoefficients), Matrix.Clone(freeCoefficients), epsilon); } stopwatch.Stop(); Console.WriteLine("Total elapsed time: " + stopwatch.Elapsed); break; } case 4: { stopwatch.Start(); for (int i = 0; i < iterations; i++) { var result = RelaxationMethod.Solve(Matrix.Clone(variableCoefficients), Matrix.Clone(freeCoefficients), epsilon, relaxationWeight); } stopwatch.Stop(); Console.WriteLine("Total elapsed time: " + stopwatch.Elapsed); break; } } }