как мне решить линейные уравнения? Вот что я попробовал
static void Main(string[] args)
{
Console.WriteLine("Enter number of equations:");
int rows = int.Parse(Console.ReadLine());
int columns = rows + 1;
float[,] table = new float[columns, rows];
for (int y = 0; y < rows; y++)
{
Console.WriteLine($"Enter values from {y+1}th row");
for (int x = 0; x < columns; x++)
{
float value = float.Parse(Console.ReadLine());
table[x, y] = value;
}
}
SolveGaussianElimination(table);
Console.ReadLine();
}
private static void SolveGaussianElimination(float[,] table)
{
for (int x = 0; x < table.GetLength(0)-2; x++)
{
for (int y = x+1; y < table.GetLength(1); y++)
{
var a = table[x, x];
var b = table[x, y];
for(int i = 0; i < table.GetLength(0); i++)
{
table[i, y] = table[i, y] * a - table[i, x] * b;
}
}
PrintTable(table);
}
}
PrintTable - это просто простая функция для распечатки таблицы. Но я застрял после «обнуления» нижней левой части треугольника. Как обнулить верхнюю правую часть треугольника? Вот что я получу, если введу эти значения:
8 -1 -2 0
-1 7 -1 10
-2 -1 9 23
8,00 -1,00 -2,00 0,00
0,00 55,00 -10,00 80,00
0,00 -10,00 68,00 184,00
8,00 -1,00 -2,00 0,00
0,00 55,00 -10,00 80,00
0,00 0,00 3640,00 10920,00
РЕДАКТИРОВАТЬ: я хочу получить его в этом формате
1,00 0,00 0,00 1,00
0,00 1,00 0,00 2,00
0,00 0,00 1,00 3,00