ARRY EXEEDS RANDOM NUMBER

2 views (last 30 days)
hi i receive this message in matlab when i run a monte carlo probllem
Requested 1000000x10000 (74.5GB) array exceeds maximum array
size preference. Creation of arrays greater than this limit
may take a long time and cause MATLAB to become
unresponsive. See array size limit or preference panel for
more information.
Error in Z12R2the (line 14)
y=0.5.*(yv-yh)+0.5.*(yv+yh).*cos(2.*PSI);
Error in impedance_antennaR_new_2d (line 82)
fn=Z12R2the(r,PSI);
i can change this preference? i want to run the MC with 1e6 randon mumbers
thank you
George
  2 Comments
David Hill
David Hill on 18 Aug 2021
There are various ways around a size limit. Why not loop through a number of times? Additional code would be helpful to make suggestions.
george veropoulos
george veropoulos on 19 Aug 2021
Hi i use the following line
n=1e5;
PSI=random('unif',psi1,psi2,[1,n]);
pd = makedist('Normal', 'mu', h0, 'sigma', st);
t = truncate(pd,h1,h2);
r = random(t,1e4,1);
when i change the tandom numbers form 1e4 -> 1e5 i receive the message about memory
George

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 19 Aug 2021
PSI=random('unif',psi1,psi2,[1,n]);
That is a row vector
r = random(t,1e4,1);
That is a column vector
fn=Z12R2the(r,PSI);
You are passing in the column vector and the row vector
y=0.5.*(yv-yh)+0.5.*(yv+yh).*cos(2.*PSI);
The 2.*PSI part will be the row vector.
Without seeing more code, we cannot be certain, but the implication is that most likely yv and yv are a column vector the size of r.
When you try to combine a column vector with 1e5 elements, with a row vector with 1e4 elements, that is generally legal in MATLAB, and MATLAB would try to create a 1e5 x 1e4 array that contained all combinations -- like
r1c1 r1c2 r1c3 r1c4 .... r1c10000
r2c1 r2c2 r2c3 r2c4 .... r2c10000
...
r100000c1 .............. r100000c10000
That would require 1e5 * 1e4 * 8 bytes, which is almost certainly a lot more than you have on your system.
If you did manage to create an array that size, then MATLAB would immediately need to create another array that size in order to finish the addition part of the assignment.
If you have enough free space, it is probably possible to configure your MATLAB and your operating system to permit MATLAB to go ahead and create arrays that large. However, the resulting operations would be quite slow, as it would write a lot of information to disk.
As your variables are random, it is unlikely that you need to have all of those in memory at one time. You would be better off running with 1e4 r values and accumulating statistics for 10 of those runs.
  5 Comments
george veropoulos
george veropoulos on 20 Aug 2021
YES work with 1e6 random number !!
george veropoulos
george veropoulos on 21 Aug 2021
i change the column vector with column and the code is runing with 1e6 random number
thank !

Sign in to comment.

More Answers (1)

Jan
Jan on 19 Aug 2021
If you request 74.5GB of RAM for a matrix, care for having this size of memory plus some head room. On a 160 GB RAM machine, the code will run.
Did you follow the advice in the error message already:
See array size limit or preference panel for more information.
?
  5 Comments
Walter Roberson
Walter Roberson on 19 Aug 2021
Divide the run up into batches that each fit into memory, and accumulate statistics as necessary.
george veropoulos
george veropoulos on 19 Aug 2021
I dont know how can i make this

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!