Maximum recursion limit of 500 reached error in matlab.

I have downloaded matlab file "Random vectors with fixed sum" I got following error
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available
stack space can crash MATLAB and/or your computer.
Error in randfixedsum
I attach file Random vectors with fixed sum. how to solve this error.

 Accepted Answer

Remove the three lines you added,
m=6;n=6; a=0.3; b=0.5;s=2
[x,v] = randfixedsum(n,m,s,a,b)
set(0,'RecursionLimit',N)
Now in a different .m file, put in
m=6;n=6; a=0.3; b=0.5;s=2
[x,v] = randfixedsum(n,m,s,a,b)

12 Comments

before posting this question I ran file without line
set(0,'RecursionLimit',N)
but I was getting error
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available
stack space can crash MATLAB and/or your computer.
so I was trying to run software with
set(0,'RecursionLimit',N)
right now also I am getting same error without adding
set(0,'RecursionLimit',N)
Removing the line that changes the RecursionLimit is not enough. Remove the other two lines that you added from randfixedsum, as Walter told you to do, and create a NEW file with those two lines.
how to make sum of all element of each row of matrix x will be 1 and all row element has uniform probability i.e. x matrix as follows
0.31 0.34 0.35
0.35 0.32 0.33
0.32 0.36 0.32
so all row has sum 1. how to do it
Use the unmodified randfixedsum code. Call it with
number_of_rows = 3; number_of_cols = 3;
randfixedsum(number_of_rows, number_of_cols, 1, 0, 1)
but it not giving matrix with each row elements have sum 1, and also not giving uniform row probability matrix. matrix given as follow
0.6312 0.2121 0.1863
0.2046 0.6227 0.6449
0.1642 0.1652 0.1688
it giving each column elements sum 1. so how to make matrix with each row elements have sum 1 and each row has a uniform probability.
number_of_rows = 3;
number_of_cols = 3;
randfixedsum(number_of_cols, number_of_rows, 1, 0, 1).'
but now also it showing matrix with column has sum 1. i.e.
0.1954 0.0836 0.5476
0.4090 0.1279 0.0607
0.3955 0.7885 0.3918
and I run randfixedsum with
m=6;n=6; a=0.3; b=0.5;s=2
[x,v] = randfixedsum(n,m,s,a,b)
then also it not showing uniform probability i.e.
0.0745 0.0015 0.4488 0.2565
0.1152 0.7316 0.0836 0.1264
0.7780 0.2247 0.4614 0.1381
0.0322 0.0423 0.0061 0.4789
so I think we can not generate uniform matrix with randfixedsum file
You left out the .' that I showed, which you need to apply to x
I tried with below
number_of_rows = 3;
number_of_cols = 3;
randfixedsum(number_of_cols, number_of_rows, 1, 0, 1).'
but it was showing
0.1954 0.0836 0.5476
0.4090 0.1279 0.0607
0.3955 0.7885 0.3918
so column sum is 1 and probability is not uniform, but how to make each row sum 1 and each row probability uniform.
m=6;n=6; a=0.3; b=0.5;s=2;
[temp,v] = randfixedsum(n,m,s,a,b);
x = temp.';
x
sum(x,2)
x =
0.344556270423524 0.343748212196347 0.318131667330222 0.324435380165784 0.309575941009429 0.359552528874694
0.337592299430687 0.306821719909737 0.315595147992029 0.333804715461032 0.300376494780825 0.40580962242569
0.35327875168311 0.332658050482519 0.36642338182394 0.321747886842974 0.319869877982517 0.306022051184939
0.333180831134916 0.305527486395052 0.320299423810174 0.377109984618907 0.332173142136238 0.331709131904713
0.330073829868122 0.321594208663405 0.34036277845982 0.303490241271701 0.367018116444669 0.337460825292284
0.332739254722547 0.336517260570612 0.334155061445051 0.349402972140701 0.328319910450661 0.318865540670428
ans =
2
2
2
2
2
2
x = randfixedsum(3, 3, 1, 0, 1).'
x =
0.623913691422786 0.213529708859028 0.162556599718185
0.28243434948114 0.441212116298064 0.276353534220796
0.0484686748538971 0.684546805251868 0.266984519894235
>> sum(x,2)
ans =
1
1
1
Thank you Walter Roberson
Please Accept an answer if the Question is solved.

Sign in to comment.

More Answers (1)

The code for ‘randfixedsum’ was written to have each column, not each row, of the resulting matrix x have the given sum s. If you want the rows to have the given sum, you will have to do a transpose on x.
As to the question of uniformity, there is a profound difference between a statistically uniform distribution and a strictly uniform distribution. The example of the figure which I included in the file exchange entry for randfixedsum at:
http://www.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum
has the values m = 3, n = 16384, s = 1.25, a = 0, and b = 1. This means that in each of the 16384 columns of the output x the sum of the three elements (xyz coordinates) must equal 1.25, and all element values must lie between 0 and 1. In the figure this implies that all the red dots must lie within the planar hexagon shown there, and their distribution throughout the hexagon is uniform in a statistical sense, though not in a strict sense. Of course, in your example with only three samples (columns) the statistical uniformity cannot be very evident - a figure illustrating it would have only three dots at some random locations within the corresponding hexagon (or triangle.)

Categories

Community Treasure Hunt

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

Start Hunting!