Help reducing memory usage during large matrix multiplication

9 ビュー (過去 30 日間)
Hayao
Hayao 2018 年 5 月 29 日
コメント済み: Sergey Kasyanov 2018 年 6 月 9 日
I have a certain 343-by-343 matrix V3 and a certain 343-by-1 vector V2 produced by certain algorithm and I want to do the following operation:
V4 = V3*(V2-I*C)
where I = eye(343), and C is a vector of zeros except for the 172th element, which is 1. I provided V3 and V2 as a workspace file in attachment. The size for V2 is actually big despite only having 343 elements because the elements contain symbols (namely "t") and a lot numbers. But the lengthy values of these elements are crucial.
The problem is, the memory usage during the calculation is about 14.5 GB (out of 15.284 GB available), and the calculation is quite slow. Since I am planning to do much larger scale calculations, this is very problematic to me.
Is there any workaround to prevent using so much RAM? Or is there nothing I can do other than to expand the RAM?
  2 件のコメント
KSSV
KSSV 2018 年 5 月 29 日
Why don't you, substitute value of t, convert it to double and then multiply?
Hayao
Hayao 2018 年 5 月 29 日
編集済み: Hayao 2018 年 5 月 29 日
Thank you KSSV.
Well, the problem is that I am planning t = inf or t = 0:0.000002:0.005.
For the former, I know it is going to converge once I put t = inf after the calculation is ultimately finished, but I don't know if it will diverge or converge if I put t = inf before the calculation is finished.
For the latter, you are right. I could just put the values and use array calculation or for-loop. The problem is that I won't know the equation itself in case I need to rescale the value of t to something else.

サインインしてコメントする。

回答 (1 件)

Sergey Kasyanov
Sergey Kasyanov 2018 年 6 月 9 日
編集済み: Sergey Kasyanov 2018 年 6 月 9 日
I think that problem can be solved by the manual multiplication of matrices.
%note: V2=(V2-I*C) is the same V2(172)=V2(172)-1;
V2(172)=V2(172)-1;
A=vpa(zeros(length(V2),1));
V2=V2.';
for i=1:length(V2)
A(i)=sum(V3(i,:).*V2);
end
A is the answer.
  1 件のコメント
Sergey Kasyanov
Sergey Kasyanov 2018 年 6 月 9 日
Also you may use that solution. It claims less memory but It has less accuracy due to convertion integer ratio coefficients to float .
V2(172)=V2(172)-1;
A=vpa(zeros(length(V2),1));
V2=vpa(V2.');
for i=1:length(V2)
A(i)=sum(V3(i,:).*V2);
end

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by