"Out of Memory" when inverting a symbolic matrix
Show older comments
I need to set up a program using symbolic matrices. However, the mathematics apparantly becomes complicated enough that taking the inverse of a 3x3 symbolic matrix takes up too much memory. I wanted to ask how I can circumvent the memory issue. Following is the relevant code segment leading to the problem:
v=['[' sprintf('conca%d,',1:51)];
v(end)=']';
Cconc1 = str2sym(v);
clear v
v=['[' sprintf('concb%d,',1:51)];
v(end)=']';
Cconc2 = str2sym(v);
clear v
v=['[' sprintf('kk%d,',1:2)];
v(end)=']';
KK = str2sym(v);
KK = KK';
Cconc1 = Cconc1';
Cconc2 = Cconc2';
% Setting up symbolic CC matrices
CC = [Cconc1, KK(1)*Cconc1.*Cconc2, KK(1)*KK(2)*Cconc1.*Cconc2.^2];
% Concerning EE calculation:
% No difference between using \ or inv() on memory usage
% Splitting the equation into smaller sections as below also does not assist
preEEinv1 = (CC'*CC);
preEEinv2 = (inv(preEEinv1));
clear preEEinv1
EE = (preEEinv2*(CC'*DD));
% Note - CC is a 51x3 matrix, KK is a 2x1 vector, DD is a 51x1 vector
% previous attempts --> 1) EE = (CC'*CC)\(CC'*DD);
% 2) EE = inv(CC'*CC)*(CC'*DD);
The following is the error message returned when executing the code
Error using symengine
Out of memory.
Error in sym/privUnaryOp (line 1045)
Csym = mupadmex(op,args{1}.s,varargin{:});
Error in sym/inv (line 22)
X = privUnaryOp(A, 'symobj::inv');
Error in sym_r (line 98)
preEEinv2 = (inv(preEEinv1));
As I am not used to getting out of memory errors on my PC, I'm a little out of my depth. Also, if you require information regarding my hardware, I am working with 16 GB RAM, a i7 3.60 GHz processor, and 65 GB virtual space.
The error line indication is always where the inverse is taken. I don't make unnecessary copies of data, and cannot use sparse matrices. The tall function does not work for the symbolic toolbox either. I have tried inverting much simpler symbolic matrices to make sure the function is sound, and it worked. Is there a way I can bypass or solve the memory issue?
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!