个人资料

主页 博客 留言板 搜索
跳过导航链接首页 > 博客列表 > 博客正文

C#求解三对角矩阵数值解法-追赶法

分类

使用追赶法求解三对角矩阵

class MatrixSolver
{
 
    //系数矩阵
    private double[,] Matrix;
    private double[] Right;
    private double[] Result;
    private double[] Beta;
    private double[] Y;
    int N;
 
    public MatrixSolver(double[,] M, double[] F)
    {
        N = Right.Length;
        Matrix = M;
        Right = F;
        Result = new double[N];
        Beta = new double[N];
        Y = new double[N];
    }
 
 
    public double[] Caculate()
    {
        Beta[0] = Matrix[0, 1] / Matrix[0, 0];
        for (int i = 1; i < N-1; i++)
        {
            Beta[i] = Matrix[i, i + 1] / (Matrix[i, i] - Matrix[i, i - 1] * Beta[i - 1]);
        }
        Y[0] = Right[0] / Matrix[0, 0];
        for (int i = 1; i <N; i++)
        {
            Y[i] = (Right[i] - Matrix[i, i - 1] * Y[i-1]) / (Matrix[i,i] - Matrix[i,i-1] * Beta[i-1]);
        }
        Result[N - 1] = Y[N - 1];
        for (int i = N-2; i >0; i--)
        {
            Result[i] = Y[i]-Beta[i]*Result[i+1];
        }
        return Result;
    }
 
 
 
 
 
 
}



songshizhao
最初发表2017/9/11 1:06:57 最近更新2017/9/11 1:06:57 1375
为此篇作品打分
10