Hello everyone!
I am kindly asking your help to solve a MATLAB “out of memory” issue that I am facing with both a PC with 16 GB of RAM and the university server with 128 GB of RAM.
I am using MATLAB 2020a and my goal would be to convert, using the matlabFunction command, a 6×52 symbolic matrix (YB) with which I need to do some calculations. The reason I need to convert the matrix into a function handle is that the same operation is way faster if YB is a function than by using the subs command. Moreover, I would need to use this matrix/function as an objective function within a genetic algorithm, so I really need YB to be a function. YB is a sparse matrix (density of 50.3%), so I tried to set the matlabFucntion MATLAB command as:
YB_fnc=matlabFunction(YB,'Optimize',false,'Sparse',true);
But by using either the Optimize option set to true or false the “out of memory” problem still remains. The same thing happens with the Sparse option set to true or false. If I run the command whos, the answer is that the YB matrix occupies 8 Bytes. Even if not the ideal solution at all, I tried to use the matlabFunction on each element of the YB matrix using a for loop, but the “out of memory” problem persists.
I tried to simplify the matrix elements using vpa and/or combine to see if the matlabFunction would be affected, but the result is always the same. I also tried to use the simplify command, both on the full YB matrix and on its single elements, but I still get “out of memory”. If trying to simplify one single element of the YB matrix at the time (using a for loop as reported), the “out of memory” message appears when trying to simplify the element (1,17) of YB.
% Simplification of hte frist row of YB
YB_simpl_1=sym(zeros(1,Nc));for j=1:52 YB_simpl_1(j)=simplify(YB(1,j));end
I really don’t understand what makes the algorithm to use so much memory or how to fix this problem. My only guess is that the mathematical expressions on each elements of the YB matrix are too long (if I try to print the content of an element of the YB matrix on the Command Window I get an expression with a long series of sin and cos functions that, at the end, is truncated by the text exceeds the maximum line length for Command Window), but I cannot modify them because they are a result of previous calculations.
Could you please help me? I really have no idea of how to fix this problem.
Thank you very much!
Andrea
Best Answer