Inverse huge matrix with tall array
Show older comments
Hi,
I am trying to find x in my system Ax=b. A is a huge matrix, it is a size of 10 billion *9, and out of my memory, b is 10 billion *1 vector.
Therefore, I am using tall array, while I don know how to compute the inverse of A? (pseudo inverse)
One answer is here, while it is incorrect: https://uk.mathworks.com/matlabcentral/answers/530823-taking-the-inverse-of-a-tall-array-to-solve-a-linear-system-of-equations
A = tall(ds);
b_t = tall(ones(1,1));
SOL = gather(A\b);
This code works with SOL is 9*1 vector, however, the vector b_t has all elements equal to 1.
If I use my verctor b, it shows an error with incompatible tall array argument in tall/qrLeftSolve.
Any one can help this case?
Thanks in advance.
Answers (2)
Hi chen, I am writing some lines code and find they are working fine. You can directly solve equeation AX=B or get x_inv by tall array. Would you please share more information, like MATLAB version and full error message?
A=tall(rand(100,100));
B1=tall(rand(100,1));
X=A\B1; % solve X in equation A*X=B1
B2=tall(eye(100));
X_inv=A\B2; % solve inv(X)
X=gather(X)
X_inv=gather(X_inv)
Ayush Modi
on 21 Jun 2024
Edited: Ayush Modi
on 21 Jun 2024
Hi Chen,
"If I use my verctor b, it shows an error with incompatible tall array argument in tall/qrLeftSolve."
Operator '\' requires both the inputs to be of same type. If either one is tall array and the other one is not, this error will be thrown. To resolve the error, you would need to convert b vector into a tall array.
Here is the sample code for your reference:
% Defining two random matrix
A = rand(100,100)
b = rand(100,1)
% Converting them to tall arrays
tallA = tall(A)
tallb = tall(b)
% We can do operation A\b
A\b
% We can also do tallA\tallb
gather(tallA\tallb)
% ERROR - if they are different
gather(tallA\b) % Note b is matrix, not tall array
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!