Gauss完全主元法(C#实现)——计算方法
代码思路: Gauss完全主元法是在高斯消元法的基础上增加了找主元,换行,换列这三个方法,因此它可以继承高斯消元法类,如有需要可以看我在计算方法分类专栏写的,各种方法都有,很详细。
1.Gauss2(Gauss完全主元法)类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Line
{
class Gauss2:Gauss
{
int[] z;
public double Findikjk(int k, ref int ik, ref int jk)
{
double max = 0;
ik = 0; jk = 0;
for (int i = k; i < n; i++)
{
for (int j = k; j < n; j++)
{
if (Math.Abs(a[i, j]) > max)
{
max = Math.Abs(a[i, j]);
ik = i; jk = j;
}
}
}
return max;
}
public void Exchangi(int k, int ik)
{
if (k != ik) //换行
{
for (int j = k; j < n + 1; j++)
{
double t = a[k, j];
a[k, j] = a[ik, j];
a[ik, j] = t;
}
}
else return;
}
public void Exchangj(int k, int jk)
{
if (k != jk) //换列
{
for (int i = k; i < n; i++)
{
double t = a[i, k];
a[i, k] = a[i, jk];
a[i, jk] = t;
}
int r = z[k];
z[k] = z[jk];
z[jk] = r;