private static double[][] FindLU(Slae slae) { double[][] LU = new double[slae.N][]; for (int i = 0; i < LU.Length; i++) { LU[i] = new double[slae.N]; } for (int i = 0; i < slae.N; i++) { Parallel.For(i, slae.N, j => { double sum = 0; for (int k = 0; k < i; k++) { sum += LU[i][k] * LU[k][j]; } LU[i][j] = slae.Matrix[i][j] - sum; }); Parallel.For(i + 1, slae.N, j => { double sum = 0; for (int k = 0; k < i; k++) { sum += LU[j][k] * LU[k][i]; } LU[j][i] = (slae.Matrix[j][i] - sum) / LU[i][i]; }); } return(LU); }
public FormExecute(Slae slae, List <ISlaeSolvingMethod> solvingMethods, bool lightMode = false) { if (solvingMethods.Count == 0) { throw new ArgumentException("Solving Methods count = 0"); } else { InitializeComponent(); this.slae = slae; this.solvingMethods = solvingMethods; results = new double[solvingMethods.Count][]; this.lightMode = lightMode; if (!lightMode) { totalT = new TimeSpan(); ConfigurePerfomanceCounters(); } else { CleanupWnd(); } } }
public double[] Solve(Slae slae) { double[][] LU = FindLU(slae); var Y = FindY(slae, LU); var X = FindX(slae, LU, Y); return(X); }
public double[] Solve(Slae slae) { // Preparation : copying arrays of slae // cuz, u know, it changes data in Slae // object if we'll use data from slae object properly double[][] A = new double[slae.N][]; Parallel.For(0, slae.N, (i) => { A[i] = new double[slae.N]; System.Array.Copy(slae.Matrix[i], A[i], slae.N); }); double[] B = new double[slae.N]; Array.Copy(slae.B, B, slae.N); ForwardElimination(A, B, slae.N); return(BackSubstitution(A, B, slae.N)); }
public static void FillDgv(DataGridView dgvData, Slae slae) { if (slae.N <= 650) { FormEditor.CreateDgvTable(dgvData, slae.N); for (int i = 0; i < slae.N; i++) { for (int j = 0; j < slae.N + 1; j++) { dgvData[j, i].Value = slae[i, j]; } } } else { throw new ArgumentException("N > 650, unable to show this slae in the form"); } }
public double[] FindX(Slae slae, double[][] LU, double[] y) { double[] x = new double[slae.N]; for (int i = slae.N - 1; i >= 0; i--) { double sum = 0; for (int k = i + 1; k < slae.N; k++) { sum += LU[i][k] * x[k]; } x[i] = (y[i] - sum) / LU[i][i]; } return(x); }
private double[] FindY(Slae slae, double[][] LU) { double[] y = new double[slae.N]; for (int i = 0; i < slae.N; i++) { double sum = 0; for (int k = 0; k < i; k++) { sum += LU[i][k] * y[k]; } y[i] = slae.B[i] - sum; } return(y); }
private void BtnRandomInput_Click(object sender, EventArgs e) { btnRandomInput.Text = "Generating"; btnRandomInput.Enabled = false; try { Slae = new Slae((int)numudRandomN.Value); } catch (Exception exc) { NotificationManager.ShowError(exc); } finally { GC.Collect(); btnRandomInput.Text = "Generate"; btnRandomInput.Enabled = true; } }
private void BtnFileInput_Click(object sender, EventArgs e) { OpenFileDialog ofd; if ((ofd = new OpenFileDialog()).ShowDialog() == DialogResult.OK) { try { using (var stream = ofd.OpenFile()) { Slae = SlaeIO.Read(stream); } NotificationManager.ShowInfo("Reading completed successfully"); } catch (Exception exc) { NotificationManager.ShowError(exc); } } }
public static void Write(double[][] matrix, double[] b, Stream stream) { Write(Slae.GetSLAEString(matrix, b), stream); }
public static void Write(Slae slae, Stream stream) { Write(slae.GetSLAEString(), stream); }
public FormShowMatrix(Slae slae) { InitializeComponent(); FillDgv(dgvData, slae); }
private void BtnClear_Click(object sender, EventArgs e) { Slae = null; }
private void BtnManualInput_Click(object sender, EventArgs e) { new FormEditor((val) => Slae = val).ShowDialog(); }