faster leftdivide given prior information

1 view (last 30 days)
Hi,
Among other calculation in my code there is a part where i use :
c=A\b;
Where A is sparse diagonal matrix (~100k x 100k) .
I am not sure whether checking of the matrix A properties takes considerable time or not.
Given that i already know that A is diagonal, is it possible to speed up the computation and avoid checkups for choosing solver?
thanks in advance,
redi

Accepted Answer

Steven Lord
Steven Lord on 16 Dec 2019
The linsolve or decomposition functions may be of interest to you. decomposition may be particularly beneficial if you're solving multiple systems with the same A matrix.
Though if you're certain A is a diagonal matrix, I'd probably try calling diag then using element-wise division between b and that diagonal (or if possible skipping creating A altogether and just create its diagonal as a vector instead.)
  1 Comment
Christine Tobler
Christine Tobler on 17 Dec 2019
Note linsolve only supports dense matrices, so wouldn't be ideal here. In general, decomposition can be used to skip some input checking in A\b. But I agree for a diagonal matrix, the cheapest will be to just compute the diagonal vector d (as a column vector, e.g. by call d = diag(A)) and call d.\b instead.

Sign in to comment.

More Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!