static void Main(string[] args) { #region Filling P_Filling(); Sources_Filling(); calc_g_pract(); calcA(); calcB(); #endregion double[,] I = new double[K, K]; for (int i = 0; i < K; i++) { I[i, i] = alpha; } SLAE.SumTwoMatrixes(I, A); double[] p = SLAE.Gauss(A, b); for (int i = 0; i < Kz; i++) { for (int j = 0; j < Kx; j++) { Console.Write("{0:0.##}\t", p[i * Kz + j]); } Console.WriteLine(); } }
/// <summary> /// 10. Создание СЛАУ /// </summary> /// <returns></returns> private static async Task SlaeCreateAndReadTests() { using (SLAE slae = new SLAE("10")) { await slae.ClearAsync(); await slae.SparseMatrixRepSeq.AddRowAsync(new double[] { 0.11, 1.11, 2.22, 0, 0, -5.55, 0, 0, -8.88, -9.99 }); await slae.SparseMatrixRepSeq.AddRowAsync(new double[] { 4, 0, 2, 0, 0, -5, 0, 0, -9, -10 }); await slae.SparseMatrixRepSeq.AddRowAsync(new double[] { 2, 1, 0, 0, 0, -6, 0, 0, -4, -20 }); await slae.SparseMatrixRepSeq.AddRowAsync(new double[] { 1, 0, 8, 0, 0, -5, 0, 0, -1, -30 }); await slae.SparseMatrixRepSeq.PrintMatrix(); Console.WriteLine("-------------------\n"); double[] seq0 = new double[] { -5.55, 0, 15, 211, 0.09 }; var tuple0 = await slae.SparseMatrixRepSeq.AddRowsSequenceBandAsync(seq0, 4, 0, 11); await slae.SparseMatrixRepSeq.PrintMatrix(); Console.WriteLine("-------------------\n"); double[] seq1 = new double[] { -1, -2, -3 }; var tuple1 = await slae.SparseMatrixRepSeq.AddRowsSequenceAsync(seq1, new int[] { 5, 6 }, new int[] { 2, 1 }); await slae.SparseMatrixRepSeq.PrintMatrix(); try { await slae.SetRightSideAsync(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }); await slae.PrintRightSide(); try { long elapsedTime = await slae.SolveCuda(); Console.WriteLine($"Время решения СЛАУ: {elapsedTime} мс"); } catch (Exception exc) { Console.WriteLine(exc.Message); } await slae.PrintResult(); } catch (Exception exc) { Console.WriteLine(exc.Message); } } Console.WriteLine("---Successful end of method---"); }
public Vector Solve(SLAE system) { if (!system.SystemMatrix.IsNonDegenerate()) { throw new Exception(methodIsNotApplyableString); } Matrix low, up; DetermineLowAndUpMatrix(system.SystemMatrix, out low, out up); return(new SLAE(up, new SLAE(low, system.RightPart).InitialOrderSolution(true)).InitialOrderSolution(false)); }
public Vector Solve(SLAE system) { if (!system.SystemMatrix.IsNonDegenerate()) { throw new Exception(methodIsNotApplyableString); } double alpha = RandomNumber(0, 2.0 / (system.SystemMatrix.Transposed() * system.SystemMatrix).FirstNorm); Matrix bMatrix = Matrix.UnaryMatrix(system.SystemMatrix.ColumnsCount) - alpha * system.SystemMatrix.Transposed() * system.SystemMatrix; Matrix HMatrix, FMatrix; DivideMatrix(bMatrix, out HMatrix, out FMatrix); Vector gVector = alpha * system.SystemMatrix.Transposed() * system.RightPart; Vector xCurrent = new double[system.SystemMatrix.ColumnsCount], xPrev; int count = 0; do { xPrev = xCurrent; xCurrent = new double[system.SystemMatrix.ColumnsCount]; Vector prevPart = FMatrix * xPrev + gVector; for (int i = 0; i < xCurrent.Count; i++) { xCurrent[i] = prevPart[i]; for (int j = 0; j < i; j++) { xCurrent[i] += xCurrent[j] * HMatrix[i, j]; } } count++; } while (!(bMatrix.FirstNorm > 0.5 && bMatrix.FirstNorm < 1 && bMatrix.FirstNorm / (1 - bMatrix.FirstNorm) * (xCurrent - xPrev).FirstNorm <= epsilan || (xCurrent - xPrev).FirstNorm <= epsilan || count == maxIterationCount)); if (count == maxIterationCount) { throw new Exception(string.Format(iterationOverflowString, count)); } return(xCurrent); }
public double[] SolveWithSimpleMetodForPFwithWeakAndSmoothCore(int _n) { N = _n; //формуємо вектор що задає праву чатину рівняння праву чатину рівняння g = new double[4 * N]; // 2*N значення з функцією gReal і 2*N значення з функцією gIm double temp = 0; h = (b - a) / (2.0 * N); for (int i = 0; i < 2 * N; i++) { temp = i * h; g[i] = gReal(temp); g[i + 2 * N] = gIm(temp); } // формуємо матрицю A, тобто дискретний вигляд системи інтегральних рівнянь A = new double[4 * N, 4 * N]; double ti = 0, tauj = 0; // визначаємо кокфіцієнти що відповідатиметь на miu1(tauj) for (int i = 0; i < 2 * N; i++) { ti = i * h; H11.Prepare(ti); H12.Prepare(ti); H2.Prepare(ti); // коефіцієнти будуються за тригонометричними квадратурними формулами for (int j = 0; j < 2 * N; j++) { tauj = j * h; // перше рівняння A[i, j] = A[i + 2 * N, j + 2 * N] = Math.PI * H12.GetValue(tauj) / N + H11.GetValue(tauj) * 2.0 * Math.PI * Integral.CoefficientForWeakSingular(H11.Param, N, tauj); A[i, j + 2 * N] = -Math.PI * H2.GetValue(tauj) / N; // друге рівняння A[i + 2 * N, j] = Math.PI * H2.GetValue(tauj) / N; } } return(SLAE.LU_methodSolving(A, g, 4 * N)); }
public Vector Solve(SLAE system) { for (int i = 0; i < system.EquasionsCount; i++) { if (system[i, i] == 0) { int index = system.FindNoZeroColumn(i, i); if (index == -1) { throw new Exception(SLAE.ResponseAboutExceptionalSolution(system[i] == 0)); } system.SwapColumns(i, index); } system.MakeCoeficientEqualToOne(i, i); system.MakeDownEqualToZero(i, i); } return(system.InitialOrderSolution(false)); }
public Vector Solve(SLAE system) { if (!system.SystemMatrix.IsNonDegenerate()) { throw new Exception(methodIsNotApplyableString); } double alpha = RandomNumber(0, 2.0 / (system.SystemMatrix.Transposed() * system.SystemMatrix).FirstNorm); Matrix bMatrix = Matrix.UnaryMatrix(system.SystemMatrix.ColumnsCount) - alpha * system.SystemMatrix.Transposed() * system.SystemMatrix; Vector gVector = alpha * (system.SystemMatrix.Transposed() * system.RightPart); Vector xCurrent = new double[system.SystemMatrix.ColumnsCount], xPrev; int count = 0; do { xPrev = xCurrent; xCurrent = bMatrix * xPrev + gVector; count++; } while (!(bMatrix.FirstNorm > 0.5 && bMatrix.FirstNorm < 1 && bMatrix.FirstNorm / (1 - bMatrix.FirstNorm) * (xCurrent - xPrev).FirstNorm <= epsilan || (xCurrent - xPrev).FirstNorm <= epsilan || count == maxIterationCount)); if (count == maxIterationCount) { throw new Exception(string.Format(iterationOverflowString, count)); } return(xCurrent); }