【发布时间】:2016-10-10 12:37:21
【问题描述】:
我最近实现了来自 Numerical Recipe 2nd edition 的 LUDecomposition 例程,称为 bandec()。它使用紧凑形式的带状矩阵创建 lu 分解(它还以紧凑形式返回 L 和 U)。我的问题是,我如何求解方程组
A.x=B,如果 x 是矩阵?
有没有我可以使用的例程?
【问题讨论】:
我最近实现了来自 Numerical Recipe 2nd edition 的 LUDecomposition 例程,称为 bandec()。它使用紧凑形式的带状矩阵创建 lu 分解(它还以紧凑形式返回 L 和 U)。我的问题是,我如何求解方程组
A.x=B,如果 x 是矩阵?
有没有我可以使用的例程?
【问题讨论】:
你写了“稀疏带状”。虽然没有针对带状情况的特殊稀疏求解器,但可以使用 LAPACK 的(密集)带状求解器。我写这篇文章的机会很小,可能实际上是你的情况。
例如,
restart;
with(LinearAlgebra):
N:=10000:
M:=RandomMatrix(N,datatype=float[8]):
V:=RandomVector(N,datatype=float[8]):
infolevel[LinearAlgebra]:=1:
X:=CodeTools:-Usage(LinearSolve(M,V)):
LinearSolve: using method LU
LinearSolve: calling external function
LinearSolve: NAG hw_f07adf
LinearSolve: NAG hw_f07aef
memory used=0.75GiB, alloc change=0.78GiB, cpu time=16.24s, real time=4.30s, gc time=8.00ms
Norm(M.X-V);
unknown: NAG hw_f06paf
unknown: NAG hw_f06paf
Norm: calling external function
Norm: NAG: hw_f06raf
-8
1.06381179421077832 10
restart;
with(LinearAlgebra):
N:=10000:
B:=max(1,floor(0.005*N)):
2*B+1;
101
M:=RandomMatrix(N,shape=band[B,B],datatype=float[8]):
V:=RandomVector(N,datatype=float[8]):
infolevel[LinearAlgebra]:=1:
X:=CodeTools:-Usage(LinearSolve(M,V)):
LinearSolve: using method LU
LinearSolve: calling external function
LinearSolve: CLAPACK hw_dgbtrf_
LinearSolve: CLAPACK hw_dgbtrs_
memory used=13.09MiB, alloc change=11.52MiB, cpu time=20.00ms, real time=23.00ms, gc time=0ns
Norm(M.X-V);
Multiply: calling external function
Multiply: NAG hw_f06pbf
Multiply: calling external function
Multiply: NAG hw_f06pbf
Norm: calling external function
Norm: NAG: hw_f06raf
-11
8.03126454229641240 10
【讨论】:
常规命令 LinearAlgebra:-LinearSolve 处理该问题。如果 B 是一个矩阵,那么 x 也是。
【讨论】: