Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
16
Добавлен:
20.06.2014
Размер:
1.58 Кб
Скачать
//Amount elements to use and they size init
//n is use as global variable, n is a size of quad matrix

float[,] matrix;
float[] a;
float[] b;

a=new float[n];//variable a[],solve
b=new float[n];//vector b[], last column in DataGridView
matrix=new float[n, n];//matrix[], DGV without last column


//Fill matrix with elements from DataGridView
//size of DGV and matrix is match

matrix[i, j] = float.Parse(/*DGV options*/);
b[i] = float.Parse(/*DGV options*/);



//Main function
//Method of Gauss included
float temp = 0;
for (int i = 0; i < n; i++)
{
if (matrix[i, i] == 0)
{
for (int j = 0; j < n; j++)
{
if (j == i)
continue;

if (matrix[j, i] != 0 && matrix[i, j] != 0)
{
for (int k = 0; k < n; k++)
{
temp = matrix[j, k];
matrix[j, k] = matrix[i, k];
matrix[i, k] = temp;
}

temp = b[j];
b[j] = b[i];
b[i] = temp;
break;
}
}
}
}


//Result of actions
//Answer included in a[]
float s = 0;
for (int i = n - 1; i >= 0; i--)
{
for (int j = i; j < n; j++)
s += matrix[i, j] * a[j];
a[i] = (b[i] - s) / matrix[i, i];//answer or solve
}

//a[] can be exported to different controls
Соседние файлы в папке Курсовая работа. Вариант 21