• 间接平差程序实现


     首先要包含我上一篇中的那个矩阵库。

    
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace CMath
    {
        /// <summary>
        /// 线性方程,即Bx+V=0
        /// </summary>
        public class Indirect
        {
            public Matrix B
            {
                get;
                set;
            }
            public Matrix l
            {
                get;
                set;
            }
            public Matrix P
            {
                get;
                set;
            }
            /// <summary>
            /// x的维数
            /// </summary>
            public int N
            {
                get
                {
                    return B.Rows;
                }
            }
            /// <summary>
            /// 初始化方程
            /// </summary>
            /// <param name="B">系数矩阵</param>
            /// <param name="l">观测值</param>
            /// <param name="P">权阵,若为null,则初始化一个E</param>
            public Indirect(Matrix B, Matrix l, Matrix P = null)
            {
                if (B.Rows != l.Rows)
                {
                    throw new Exception("B和V的行数不相等");
                }
                else
                {
                    this.B = B;
                    this.l = l;
                    if (P == null)
                    {
                        double[,] E=new double[B.Rows,B.Rows];
                        for (int i = 0; i < B.Rows; i++)
                        {
                            for (int j = 0; j < B.Rows; j++)
                            {
                                if (i == j)
                                {
                                    E[i, j] = 1;
                                }
                            }
                        }
                        this.P = new Matrix(E);
                    }
                    else
                    {
                        this.P = P;
                    }
                }
            }
            #region 求解方程
            public Matrix GetN()
            {
                return this.B.Transpose() * this.P * this.B;
            }
            public Matrix GetW()
            {
                return this.B.Transpose() * this.P * this.l;
            }
            public Matrix Getx()
            {
                return this.GetN().Inverse() * this.GetW();
            }
            public Matrix GetV()
            {
                return this.B * this.Getx() - this.l;
            }
            public double GetSigma()
            {
                return Math.Sqrt((GetV().Transpose() * P * GetV())[0, 0] / (B.Rows-B.Cols));
            }
            public Matrix GetQvv()
            {
                return P.Inverse() - B * GetN().Inverse() * B.Transpose();
            }
            #endregion 
            public override string ToString()
            {
                Matrix V = this.GetV();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < this.N; i++)
                {
                    for (int j = 0; j < B.Cols; j++)
                        sb.Append(B[i, j] + " ");
                    for (int j = 0; j < V.Cols; j++)
                    {
                        //是否要加空格
                        string flag = "";
                        if (j != V.Cols - 1) flag = "  ";
                        sb.Append(V[i, j] + flag);
                    }
                    //判断是否换行
                    string lineflag = "";
                    if (i != this.N - 1) lineflag = Environment.NewLine;
                    sb.Append(lineflag);
                }
                return sb.ToString();
            }
        }
    }
  • 相关阅读:
    Hadoop(十六)之使用Combiner优化MapReduce
    Hadoop(十五)MapReduce程序实例
    Hadoop(十四)MapReduce原理分析
    STM32新的IDE -- stm32cubeIde 点亮个LED灯
    resin+spring-websocket 深坑
    spring Websocket 报 No suitab le default RequestUpgradeStrategy found
    nginx代理内网域名碰到的坑
    Showing Recent Issues clang: error: linker command failed with exit code 1 (use -v to see invocatio
    sublime安装插件步骤
    tomcat7 ajax请求服务中文乱码
  • 原文地址:https://www.cnblogs.com/wzxwhd/p/5971992.html
Copyright © 2020-2023  润新知