在Julia中有效解决特定的线性系统 [英] Solve a particular linear system efficiently in julia
问题描述
我广泛使用julia的线性方程求解器res = X\b
.由于参数变化,我必须在程序中使用数百万次.之所以可以,是因为我使用的尺寸较小(最大为30
).现在,我想分析更大的系统,直到1000
,线性求解器不再有效.
我认为可以解决这个问题.但是我必须说,有时我的X矩阵很稠密,有时很稀疏,所以我需要在两种情况下都能正常工作的东西.
b
向量是一个全零的向量,除了一个条目始终为1
(实际上始终为最后一个条目).而且,我不需要所有的res
向量,只需它的第一个条目即可.
如果您的问题属于(A - µI)x = b
形式,其中µ
是变量参数,而A
,b
是固定的,则可以工作对角化.
让A = PDP°
,其中P°
表示P
的倒数.然后(PDP° - µI)x = b
可以转换为
(D - µI)P°x = P°b,
P°x = P°b / (D - µI),
x = P(P°b / (D - µI)).
(/
操作表示将各个矢量元素除以标量Dr - µ
.)
对角线化了A
之后,为任何µ
计算一个解决方案将减少为两个矩阵/矢量乘积,或者,如果还可以预先计算P°b
,则为一个.
数值不稳定性将出现在特征值A
附近.
I use extensively the julia's linear equation solver res = X\b
. I have to use it millions of times in my program because of parameter variation. This was working ok because I was using small dimensions (up to 30
). Now that I want to analyse bigger systems, up to 1000
, the linear solver is no longer efficient.
I think there can be a work around. However I must say that sometimes my X matrix is dense, and sometimes is sparse, so I need something that works fine for both cases.
The b
vector is a vector with all zeroes, except for one entry which is always 1
(actually it is always the last entry). Moreover, I don't need all the res
vector, just the first entry of it.
If your problem is of the form (A - µI)x = b
, where µ
is a variable parameter and A
, b
are fixed, you might work with diagonalization.
Let A = PDP°
where P°
denotes the inverse of P
. Then (PDP° - µI)x = b
can be transformed to
(D - µI)P°x = P°b,
P°x = P°b / (D - µI),
x = P(P°b / (D - µI)).
(the /
operation denotes the division of the respective vector elements by the scalars Dr - µ
.)
After you have diagonalized A
, computing a solution for any µ
reduces to two matrix/vector products, or a single one if you can also precompute P°b
.
Numerical instability will show up in the vicinity of the Eigenvalues of A
.
这篇关于在Julia中有效解决特定的线性系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!