sample4_15.cs

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

CS
52
字号
/*
 * 示例程序Sample4_15: LEquations类的求解线性最小二乘问题的广义逆法
 */

using System;
using CSharpAlgorithm.Algorithm;

namespace CSharpAlgorithm.Sample
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
            // 系数矩阵数据
            double[] mtxDataCoef14 = {
                                         1.0,1.0,-1.0,
                                         2.0,1.0,0.0,
                                         1.0,-1.0,0.0,
                                         -1.0,2.0,1.0};
            // 常数矩阵数据
            double[] mtxDataConst14 = {
                                          2.0,
                                          -3.0,
                                          1.0,
                                          4.0};
		
            // 构造系数矩阵
            Matrix mtxCoef14 = new Matrix(4, 3, mtxDataCoef14);
            // 构造常数矩阵
            Matrix mtxConst14 = new Matrix(4, 1, mtxDataConst14);

            // 构造线性方程组
            LEquations leqs14 = new LEquations(mtxCoef14, mtxConst14);
		
            // 求解线性最小二乘问题的广义逆法
            Matrix mtxResult14 = new Matrix();
            Matrix mtxResultAP = new Matrix();
            Matrix mtxResultU = new Matrix();
            Matrix mtxResultV = new Matrix();
            if (leqs14.GetRootsetGinv(mtxResult14, mtxResultAP, mtxResultU, mtxResultV, 0.0001))
            {
                Console.WriteLine(mtxResult14);
            }
            else
            {
                Console.WriteLine("失败");
            }
        }
	}
}

⌨️ 快捷键说明

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