# Regional Geomagnetic Field Modeling Based on Associated Legendre Polynomials
## 2 Principles and Methods
### Basic Modeling Methods  
Modeling the geomagnetic field using the associated Legendre polynomials involves creating a basis function system, solving the coefficient matrix, and using the basis function series to predict observations. Assuming that the geomagnetic element of the geomagnetic field is \(B\), the basis function system is jointly constructed using the associated Legendre polynomials \(P_{j}(\Delta\varphi)P_{n-j}(\Delta\lambda)\), where \(\Delta\varphi\) and \(\Delta\lambda\) denote the normalized latitude and longitude, respectively; \(N\) denotes the maximum degree of the expansion; \(n\) indicates the order of the associated Legendre polynomial expansion; and \(A\) is the matrix of model coefficients. The associated Legendre polynomials exhibit orthogonality, which satisfies Equation (2):  
\[\int_{-1}^{1}P_{i}(x)P_{j}(x)dx= \begin{cases}0,i\
eq j\\ 2/(2n+1),i=j.\end{cases}  \tag{2}\]  
Based on this, the basic model equations of the geomagnetic field in the localized region can be constructed using Equation (3):  
\[B=\sum_{n=0}^{N}\sum_{j=0}^{n}A_{n\eta}P_{j}(\Delta\varphi)P_{n-j}(\Delta \lambda), \tag{3}\]  
which can be simplified as \(B=AD\), where the matrix \(D\) is constructed from associated Legendre polynomials, as shown in Equation (4), and \(B\) represents the observed data sequence. The coefficient matrix \(A\) is typically solved using the least squares method. However, as the truncation level of the expansion increases, its numerical instability is significantly exacerbated, often leading to failure to obtain a solution [18; 19]. Although the Cholesky decomposition method offers higher computational efficiency, it is only applicable to symmetric positive definite matrices and also faces numerical stability-related challenges at high orders [20]. The singular value decomposition (SVD) method, while effective in handling ill-conditioned matrices, presents a significant increase in computational complexity as the order rises [21]. In contrast, the QR decomposition method demonstrates outstanding numerical stability, effectively addressing ill-conditioned matrix problems in high-order polynomial fitting while maintaining moderate computational complexity and balancing precision with efficiency. Therefore, based on the comprehensive consideration of numerical stability, computational efficiency, and applicability, this study employs the QR decomposition method as the optimal approach for solving the coefficient matrix. The fundamental principle of QR decomposition lies in its orthogonalization process, which transforms the column vectors of a matrix into an orthogonal basis while generating an upper triangular matrix. This process ensures high stability and efficiency in numerical computations. In this study, QR decomposition is applied to solve the coefficient matrix of the geomagnetic field model, where its orthogonality guarantees computational accuracy, and the upper triangular structure significantly simplifies subsequent solution procedures. If the final matrix formed by the associated Legendre polynomials is \(D\), the QR decomposition method effectively preserves the stability of the numerical computation and reduces the computational complexity by transforming matrix \(D\) into an orthogonal matrix \(Q\) and an upper triangular matrix \(R\). In Equation (6), \(R^{\dagger}\) represents the pseudo-inverse of \(R\). For the upper triangular matrix \(R\), the pseudo-inverse is its inverse. \[\mathbf{D}=\left[ \begin{array}{cccc}\mathrm{P}_{0}(\Delta\varphi_{1})\mathrm{P} _{0}(\Delta\lambda_{1})&\mathrm{P}_{0}(\Delta\varphi_{1})\mathrm{P}_{1}( \Delta\lambda_{1})&\cdots&\mathrm{P}_{N}(\Delta\varphi_{1})\mathrm{P}_{0}( \Delta\lambda_{1})\\ \vdots&\vdots&\ddots&\vdots\\ \mathrm{P}_{0}(\Delta\varphi_{k})\mathrm{P}_{0}(\Delta\lambda_{k})&\mathrm{ P}_{0}(\Delta\varphi_{k})\mathrm{P}_{1}(\Delta\lambda_{k})&\cdots&\mathrm{P}_{N}( \Delta\varphi_{k})\mathrm{P}_{0}(\Delta\lambda_{k})\end{array}