简体   繁体   English

使用vertcat的Matlab错误内存不足

[英]Matlab Error using vertcat Out of memory

I am running the following code. 我正在运行以下代码。 It works for smaller NumberOfVariables, but not for any for 8 or larger due to lack of memory. 它适用于较小的NumberOfVariables,但由于内存不足,不适用于8或更大的NumberOfVariables。 I really just need the first AllAnswers that does not contain zero, but would like all AllAnswers if possible. 我真的只需要第一个不包含零的AllAnswers,但如果可能的话,需要所有AllAnswers。

NumberOfVariables = 9;
k=NumberOfVariables^2-NumberOfVariables+1;
integers = 0:k-1;
numbers = 1:k-1;
tic
s = combnk(integers,NumberOfVariables);
AllAnswers = [];
for i = 1:size(s,1)
G=combnk(s(i,:),2);
G = [(G(:,1)'-G(:,2)') (G(:,2)'-G(:,1)')];
G = sort(mod(G,k));
if (isequal(G,numbers))
AllAnswers = [AllAnswers;s(i,:)];
end
end
toc
 s = combnk(integers,NumberOfVariables);

Is the list of all Number of Variables -sized combinations of elements in integers . 是所有Number of Variables大小的integers组合的列表。 So that's a list with 所以这是一个清单

k!/((NumberOfVariables!(k-NumberOfVariables)!) ķ!/((NumberOfVariables!(K-NumberOfVariables)!)

or, since k = NumberOfVariables^2-NumberOfVariables 或者,因为k = NumberOfVariables ^ 2-NumberOfVariables

(NumberOfVariables^2-NumberOfVariables)!/((NumberOfVariables!(NumberOfVariables^2-2*NumberOfVariables)!) (NumberOfVariables ^ 2-NumberOfVariables)!/((NumberOfVariables!(NumberOfVariables ^ 2-2 * NumberOfVariables)!)

using x for NumberOfVariables, to keep this readable: 使用x表示NumberOfVariables,以保持可读性:

      (x²-x)!        x²!            x²!            x²!     
#s= ----------  > ---------- > ------------ = ------------ 
     x!(x²-2x)!   x!(x²-2x)!   x!(x²-2x+1)!    x!((x-1)²!)

you get the idea. 你明白了。 this thing is not your friend if you're actually approaching it by allocating memory for #s elements. 如果您实际上是通过为#s元素分配内存来接近它的话,那么这不是您的朋友。 In fact, looking at this, for x>=4, this will grow faster than e^x. 实际上,看着这个,对于x> = 4,它的增长速度将比e ^ x快。

For NumberOfVariables starting at 10, that simply gets incredibly large. 对于从10开始的NumberOfVariables,它变得非常大。

Do the math! 算一算!

https://www.wolframalpha.com/share/clip?f=d41d8cd98f00b204e9800998ecf8427euo0stpao37 https://www.wolframalpha.com/share/clip?f=d41d8cd98f00b204e9800998ecf8427euo0stpao37

使用Wolfram Alpha创建的图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM