How does one solve a large system of linear equations efficiently when only a few of the constant terms change. For example:
I currently have the system Ax= b. I compute the inverse of A once, store it in a matrix and each time any entry updates in b perform a matrix-vector multiplication A^-1(b) to recompute x.
This is inefficient as only a couple of entries would have update in b. Are there more efficient ways of solving this system when A-1 remains constant but specific known values change in b?
I use uBlas and Eigen, but not aware of solutions that would address this problem of selective recalculation. Thanks for any guidance.
Compute
A^-1. Ifb_iis the ith component ofb, then examined/db_i A^-1 b(the derivative of A^-1 with respect to the ith component ofb) — it equals a column ofA^-1(in particular, the ith column). And derivatives of linear functions are constant over their domain. So if you havebandb', and they differ only in the ith component, thenA^-1 b - A^-1 b' = [d/db_i A^-1] * (b-b')_i. For multiple components, just add them up (asA^-1is linear).Or, in short, you can calculate
A^-1 (b'-b)with some optimizations for input components that are zero (which, if only some components change, will be most of the components).A^-1 b' = A^-1 (b'-b) + A^-1 (b). And if you know that only some components will change, you can take a copy of the appropriate column ofA^-1, then multiply it by the change in that component of b.