sample4_12.cs

来自「C#的数值计算的几乎所有算法」· CS 代码 · 共 49 行

CS
49
字号
/*
 * 示例程序Sample4_12: LEquations类的高斯-赛德尔迭代法
 */

using System;
using CSharpAlgorithm.Algorithm;

namespace CSharpAlgorithm.Sample
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
            // 系数矩阵数据
            double[] mtxDataCoef11 = {
                                         7.0,2.0,1.0,-2.0,
                                         9.0,15.0,3.0,-2.0,
                                         -2.0,-2.0,11.0,5.0,
                                         1.0,3.0,2.0,13.0};
            // 常数矩阵数据
            double[] mtxDataConst11 = {
                                          4.0,
                                          7.0,
                                          -1.0,
                                          0.0};
		
            // 构造系数矩阵
            Matrix mtxCoef11 = new Matrix(4, mtxDataCoef11);
            // 构造常数矩阵
            Matrix mtxConst11 = new Matrix(4, 1, mtxDataConst11);

            // 构造线性方程组
            LEquations leqs11 = new LEquations(mtxCoef11, mtxConst11);
		
            // 高斯-赛德尔迭代法
            Matrix mtxResult11 = new Matrix();
            if (leqs11.GetRootsetGaussSeidel(mtxResult11, 0.0001))
            {
                Console.WriteLine(mtxResult11);
            }
            else
            {
                Console.WriteLine("失败");
            }
        }
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?