double[] msolve(double[][] m)
{
int i, j, k;
int n = m.Length;
double factor = 0;
double precision = 1e9;
double[] m1 = new double[n];
double[][] m2 = new double[n][];
for (i = 0; i < n; i++)
{
m2[i] = new double[m[i].Length];
for (j = 0; j < m[i].Length; j++)
{
m2[i][j] = m[i][j];
}
}
for (k = 1; k < n; k++) for (i = k; i < n; i++)
{
factor = m2[i][k - 1] / m2[k - 1][k - 1];
for (j = 0; j <= n; j++) m2[i][j] -= m2[k - 1][j] * factor;
}
for (i = n - 1; i >= 0; i--)
{
m1[i] = m2[i][n];
for (j = n - 1; j > i; j--) m1[i] -= m2[i][j] * m1[j];
m1[i] /= m2[i][i];
m1[i] = Math.Round(m1[i] * precision) / precision;
}
return m1;//matrix(n, 1, m1);
}
private void button1_Click(object sender, EventArgs e)
{
var d = new double[][] { new double[] { 1,1,2,8}, new double[] { -1,-2,3,1},new double []{3,-7,4,10}};
var sl = msolve(d);
}