console.error(`Unable to load nonexistent manifest entry ‘islands/voting-prompt’. Check that your file path is correct.`)

\begingroup

我正在尝试解决

假设 A 为 20000×20000 矩阵,除主对角线上的素数 2、3、5、7、…、224737 和所有位置上的数字 1 外,其余元素均为零AA{\displaystyle a_{ij}}| ij | =1,2,4,8,,16384||=124816384{\displaystyle |i-j|=1,2,4,8,\dots ,16384}的 (1, 1) 项是什么A1A1{\displaystyle A^{-1}}

Clear["Global`*"];
matrixSize = 20;
(*Generate the prime numbers along the diagonal*)
primes = Prime[Range[1, matrixSize]];

(*Create a sparse diagonal matrix with the primes on the diagonal*)
A = SparseArray[Band[{1, 1}] -> primes, {matrixSize, matrixSize}];
A

(*Create the off-diagonal elements with 1s*)
kSet = Table[2^m, {m, 0, Floor[Log[2, matrixSize - 1]]}];
offDiagonals = 
  Flatten[Table[{Band[{1 + k, 1}] -> 1, Band[{1, 1 + k}] -> 1}, {k, 
     kSet}]];

(*Add the off-diagonal elements to the matrix*)
A = A + SparseArray[offDiagonals, {matrixSize, matrixSize}];
(A = Normal@A) // MatrixForm
Dimensions@A
(*Compute the inverse of the matrix A*)
Ainv = Inverse[A, Method -> "DivisionFreeRowReduction"];

(*Extract the (1,1) entry of the inverse matrix*)
Ainv[[1, 1]]

如何在 Mathematica 中获取大尺寸矩阵(例如 20000)的逆矩阵?

有没有更有效的方法?比如奇异值分解 (SVD) (LAPACK: GESVD)?

  • 斯特拉森算法(及相关的快速矩阵乘法方法)
  • 带部分枢轴的分块 LU 分解
  • 乔莱斯基分解(用于正定矩阵)
  • 迭代方法(针对大型稀疏矩阵)
  • 近似方法(适用于非常大的矩阵)
  • 并行和基于 GPU 的实现
  • 稀疏逆方法

\endgroup


最佳答案
1

\begingroup

正如你在问题的微小实例中观察到的那样,矩阵Ainv是密集的。因此你需要矩阵大小2ArX年代2O(\mathrm{matrixSize}^2)内存来存储结果。这很快就变得不可行。此外,计算逆矩阵的所有元素可能比矩阵大小3ArX年代3O(\mathrm{matrixSize}^3),特别是当您使用整数时。

一种更快的方法是使用具有机器精度数字的稀疏直接求解器:

S = LinearSolve[N[A]];

提取条目A1=电视A1A1=电视A1A^{-1}_{ij} = e_i^T A^{-1} e_j你可以做

UnitVector[matrixSize, i] . S[ UnitVector[matrixSize, j] ]

或者

S[ UnitVector[matrixSize, j] ][[i]]

这很可能需要远远少于矩阵大小2ArX年代2O(\mathrm{matrixSize}^2)时间。(它到底有多大程度上取决于矩阵的稀疏结构。)

这可能不是最准确的方法。与0.7250783462上发布的“解决方案”相比,相对误差为。但解决方案仅给出 10 个有效数字,因此无法说我的解决方案到底有多好。9.43361*10^-11

\endgroup