public void FactorizationWithZeros4dim() { int[] rows = new int[] { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3 }; int[] collumns = new int[] { 0, 1, 0, 1, 2, 1, 2, 3, 2, 3 }; double[] values = new double[] { 100, 10, 10, 101, 20, 20, 104, 30, 30, 109 }; FA = new CoordinationalMatrix(rows, collumns, values, 4); IncompleteCholesky incompleteCholesky = new IncompleteCholesky(FA); var result = incompleteCholesky.LMult(new Vector(new double[] { 1, 1, 1, 1 })); double[] resultActual = new double[] { 10, 11, 12, 13 }; for (int i = 0; i < result.Size; i++) { Assert.Equal(result[i], resultActual[i], 8); } }
public TestDiagonal() { int[] rows = new int[] { 0, 0, 0, 1, 1, 1, 2, 2, 2 }; int[] collumns = new int[] { 0, 1, 2, 0, 1, 2, 0, 1, 2 }; double[] values = new double[] { 10, 1, 2, 1, 10, 3, 2, 3, 10 }; FA = new CoordinationalMatrix(rows, collumns, values, 3); }
public void ConstructorWithZeros(FormatFactory.Formats type) { type = FormatFactory.Formats.Skyline; var exploredMatrix = FormatFactory.Convert(coordinationalMatrix, type); var backCoordMatrix = exploredMatrix.ConvertToCoordinationalMatrix(); size = 3; values = new double[] { 1, 4, 5, 6, 2, 0, 8, 0, 3 }; columns = new int[] { 0, 1, 2, 0, 1, 2, 0, 1, 2 }; rows = new int[] { 0, 0, 0, 1, 1, 1, 2, 2, 2 }; coordinationalMatrix = new CoordinationalMatrix(rows, columns, values, size); Assert.True(new HashSet <(double, int, int)>(coordinationalMatrix).SetEquals(backCoordMatrix)); //Assert.True((coordinationalMatrix).Equals(backCoordMatrix)); //var formatFactory = new FormatFactory(); // //foreach (var type in formatFactory.formats) //{ // var exploredMatrix = FormatFactory.Convert(coordinationalMatrix, type.Key); // var backCoordMatrix = exploredMatrix.ConvertToCoordinationalMatrix(); // Assert.True(new HashSet<(double, int, int)>(coordinationalMatrix).SetEquals(backCoordMatrix)); //} }
public static IMatrix Convert(CoordinationalMatrix mat, string type) { switch (type) { case "Координатный": return(mat); case "Плотный": return(new DenseMatrix(mat)); case "Профильный": //return new SkylineMatrix(mat); return(mat); case "Строчный без выделенной диагонали": return(new SparseRowMatrix(mat)); case "Строчно-стобцовый": return(new SparseRowColumnMatrix(mat)); default: // Должны вызываться конвертеры!!!!!!!!!!!!!!!!!!!! return(mat); } }
public void Factorize(CoordinationalMatrix M) { FactorizedMatrix = (CoordinationalMatrix)M.Clone(); for (int i = 0; i < FactorizedMatrix.Size; i++) { FactorizedMatrix.Set(i, i, Math.Sqrt(FactorizedMatrix[i, i])); } }
public TestLUsq() { int[] rows = new int[] { 0, 0, 0, 1, 1, 1, 2, 2, 2 }; int[] collumns = new int[] { 0, 1, 2, 0, 1, 2, 0, 1, 2 }; double[] values = new double[] { 4, 8, 12, 6, 28, 46, 10, 44, 121 }; FA = new CoordinationalMatrix(rows, collumns, values, 3); }
public TestSimple(ITestOutputHelper testOutputHelper) { int[] rows = new int[] { 0, 0, 0, 1, 1, 1, 2, 2, 2 }; int[] collumns = new int[] { 0, 1, 2, 0, 1, 2, 0, 1, 2 }; double[] values = new double[] { 10, 1, 2, 1, 10, 3, 2, 3, 10 }; FA = new CoordinationalMatrix(rows, collumns, values, 3); _testOutputHelper = testOutputHelper; }
public TestCoordinationalMatrix() { size = 3; values = new double[] { 1, 4, 5, 6, 2, 8, 3 }; columns = new int[] { 0, 1, 2, 0, 1, 0, 2 }; rows = new int[] { 0, 0, 0, 1, 1, 2, 2 }; vector = new Vector(new double[] { 1, 1, 1 }); coordinationalMatrix = new CoordinationalMatrix(rows, columns, values, size); }
public void Foreach() { size = 3; var values = new double[] { 1, 4, 5, 4, 2, 5, 3 }; columns = new int[] { 0, 1, 2, 0, 1, 0, 2 }; rows = new int[] { 0, 0, 0, 1, 1, 2, 2 }; CoordinationalMatrix coordinationalMatrix = new CoordinationalMatrix(rows, columns, values, size); Assert.True(new HashSet <(double, int, int)>(symmetricCoordinationalMatrix).SetEquals(coordinationalMatrix)); }
public void Factorize(CoordinationalMatrix M) { D = M.Diagonal.Clone(); for (int i = 0; i < D.Size; i++) { D[i] = Math.Sqrt(D[i]); } DInvert = D.Clone(); for (int i = 0; i < DInvert.Size; i++) { DInvert[i] = 1 / DInvert[i]; } }
public void Fill() { FillFunc fillFunc = (row, col) => { return((row + 1) + (col + 1)); }; coordinationalMatrix.Fill(fillFunc); size = 3; values = new double[] { 2, 3, 4, 3, 4, 4, 6 }; columns = new int[] { 0, 1, 2, 0, 1, 0, 2 }; rows = new int[] { 0, 0, 0, 1, 1, 2, 2 }; CoordinationalMatrix coordinat = new CoordinationalMatrix(rows, columns, values, size); Assert.True(new HashSet <(double, int, int)>(coordinationalMatrix).SetEquals(coordinat)); }
public void Factorize(CoordinationalMatrix M) { FA = (CoordinationalMatrix)M.Clone(); var rows = FA.GetMatrixRows(); if (Math.Abs(FA[0, 0]) < 1.0E-14) { return; } foreach (var i in rows) { double sumD = 0; var cols_i = FA.GetMatrixColumnsForRow(i); foreach (var j in cols_i) { if (j >= i) { break; } double sumL = 0, sumU = 0; foreach (var k in cols_i) { if (k > j - 1) { break; } sumL += FA[i, k] * FA[k, j]; } FA.Set(i, j, (M[i, j] - sumL) / FA[j, j]); foreach (var k in FA.GetMatrixRowsForColumn(j)) { if (k > j - 1) { break; } sumU += FA[k, i] * FA[j, k]; } FA.Set(j, i, (M[j, i] - sumU)); sumD += FA[i, j] * FA[j, i]; } FA.Set(i, i, M[i, i] - sumD); } }
public void Factorize(CoordinationalMatrix M) { factorizedMatix = (CoordinationalMatrix)M.Clone(); var rows = factorizedMatix.GetMatrixRows(); if (Math.Abs(factorizedMatix[0, 0]) < 1.0E-14) { return; } foreach (var i in rows) { double sumD = 0; var columns = factorizedMatix.GetMatrixColumnsForRow(i); foreach (var j in columns) { if (j >= i) { break; } double sumL = 0; foreach (var k in columns) { if (k > j - 1) { break; } sumL += factorizedMatix[i, k] * factorizedMatix[j, k]; } var value = (M[i, j] - sumL) / factorizedMatix[j, j]; factorizedMatix.Set(i, j, value); factorizedMatix.Set(j, i, value); sumD += factorizedMatix[i, j] * factorizedMatix[i, j]; } factorizedMatix.Set(i, i, Math.Sqrt(M[i, i] - sumD)); } }
public void FactorizationDiag() { int[] rows = new int[] { 0, 1, 2 }; int[] collumns = new int[] { 0, 1, 2 }; double[] values = new double[] { 10, 5, 7 }; FA = new CoordinationalMatrix(rows, collumns, values, 3); IncompleteCholesky incompleteCholesky = new IncompleteCholesky(FA); var result = incompleteCholesky.LMult(new Vector(new double[] { 1, 1, 1 })); double[] resultActual = new double[] { Math.Sqrt(10), Math.Sqrt(5), Math.Sqrt(7) }; for (int i = 0; i < result.Size; i++) { Assert.Equal(result[i], resultActual[i], 8); } }
private void forwardToolStripMenuItem1_Click(object sender, EventArgs e) { bool symmetric = SLAESource.IsSymmetric; var tmp = new FormatFactory(); if (symmetric) { matrix = FormatFactory.Convert((SymmetricCoordinationalMatrix)MatrixVisualRepresentation.PatternedGridViewToCoordinational(A, symmetric), FormatFactory.FormatsDictionary[format]); } else { matrix = FormatFactory.Convert((CoordinationalMatrix)MatrixVisualRepresentation.PatternedGridViewToCoordinational(A, symmetric), FormatFactory.FormatsDictionary[format]); } if (patternChanged) { CoordinationalMatrix user = (CoordinationalMatrix)MatrixVisualRepresentation.PatternedGridViewToCoordinational(A, symmetric); CoordinationalMatrix auto = matrix.ConvertToCoordinationalMatrix(); foreach (var elem in auto) { if (!user.Contains((elem.value, elem.row, elem.col))) { var res = MessageBox.Show("Заданный портрет не соответствует выбранному формату хранения. Портрет будет автоматически преобразован к корректному виду.", "Уведомление", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (res == DialogResult.OK) { mainForm.SetSLAE(matrix, b, x0); Close(); } return; } } } mainForm.SetSLAE(matrix, b, x0); Close(); }
public static IMatrix Convert(CoordinationalMatrix matrix, Formats type) { switch (type) { case Formats.Coordinational: return(matrix); case Formats.Dense: return(new DenseMatrix(matrix)); case Formats.Skyline: return(new SkylineMatrix(matrix)); case Formats.SparseRow: return(new SparseRowMatrix(matrix)); case Formats.SparseRowColumn: return(new SparseRowColumnMatrix(matrix)); default: return(matrix); } }
public void FactorizationWithZeros() { int[] rows = new int[] { 0, 0, 1, 1, 1, 2, 2 }; int[] collumns = new int[] { 0, 1, 0, 1, 2, 1, 2 }; double[] values = new double[] { 10, 1, 1, 10, 2, 2, 10 }; FA = new CoordinationalMatrix(rows, collumns, values, 3); IncompleteCholesky incompleteCholesky = new IncompleteCholesky(FA); var result = incompleteCholesky.LMult(new Vector(new double[] { 1, 1, 1 })); double[] resultActual = new double[] { Math.Sqrt(10), Math.Sqrt(10) / 10 + 3 * Math.Sqrt(110) / 10, 2 * Math.Sqrt(110) / 33 + 5 * Math.Sqrt(418) / 33, }; for (int i = 0; i < result.Size; i++) { Assert.Equal(result[i], resultActual[i], 8); } }
public SimpleFactorization(CoordinationalMatrix M) { Factorize(M); }
public IncompleteLU(CoordinationalMatrix M) { Factorize(M); }
public IncompleteCholesky(CoordinationalMatrix M) { Factorize(M); }
public DioganalFactorization(CoordinationalMatrix M) { Factorize(M); }