File Exchange

## Multiple same-size linear solver

version 1.3.0.0 (4.74 KB) by
Solve multiple systems of linear equations of the same size

Updated 26 May 2010

Sometime we need to solve a bunch of small linear (least-square) systems of the same size. This function can accomplish this task conveniently.

The system matrix and RHS are passed as 3D arrays.

Furthermore, calling syntax can support two simplifications:
- same RHS for all systems; or
- single RHS for each system.

Followed an idea from Tim Davis (using sparse)

### Cite As

Bruno Luong (2021). Multiple same-size linear solver (https://www.mathworks.com/matlabcentral/fileexchange/24260-multiple-same-size-linear-solver), MATLAB Central File Exchange. Retrieved .

Abdel-Rahman Ashraf

If the first two dimensions are equal as I said, it won't matter. however, in general, you are right. Thanks again.

Bruno Luong

@Ashraf I believe it should be
MSOL = reshape(MSOL, [sx(2) sy(2) sx(3:dx)]);

Abdel-Rahman Ashraf

Thank you very much. I modified it a little bit to work for any number of dimensions, considering the first two dimensions are of the same size, as shown below.
M=rand(5,5,2,3,6);
RHS=[0,0,0,01];
sx = size(M);
sy = size(RHS);
dx = ndims(M);
MSOL=MultiSolver(reshape(M,sx(1),sx(2),[]),RHS);
MSOL = reshape(MSOL, [sx(1) sy(2) sx(3:dx)]);

Bruno Luong

@Ashraf: reshape your M to (5x5x36), solve the multiple linear systems then reshape back

X = MultiSolver(reshape(M,5,5,[]), RHS)
X = reshape(X,[5 1 2 3 6])

Abdel-Rahman Ashraf

Amazing solver! Can I extend SliceMultiSolver to solve an n-dim matrix where n is 1,2,3,4,5,.....?
For eample, If I have M=rand (5,5,2,3,6) and RHS=[0;0;0;0;1];, can I modify it slightly so that it can solve it?

Baris Canitez

li haitao

John Yang

Thanks for this file, shedding light to me on this kind of problems!

Rajab Legnain

Hi Sir

It is early a great function.
Thanks for sharing.
Regards

Cole Van Vlack

Hi Bruno,

I tried your function on a large array (eg. 5*5*1000000), it occupies too much memory. It will take at least 5 times memory as the initial data package. And most of the memory cost is to store the sparse indexes. Is there any way to reduce the memory consuming? Thanks!

Cheers,
Xiaodong

##### MATLAB Release Compatibility
Created with R2009a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux