It's not easy being a beginner!
Ok..I'm trying to add some bias to the following random walk in values. Here's the example code:
for i=1:20; % Let j = probability for specific value % Let k = the probability that two adjacent values will be equal
j =rand; k =rand;
if 0<=k<=.0063 value(i+1)=value(i);
elseif 0<=j<=.0687 value(i+1)=0;
elseif .0688<=j<=.1880 valuei+1)=1;
elseif .1881<=j<=.3286 value(i+1)=2;
How would I add a constraint (or bias) the above random walk so that every 10 adjacent values (of the 20 random values that will be generated by the above code) must maintain a moving average with the value of 1?
I hope i'm clear on what I'm trying to do. Thanks for all the help in advance!
No products are associated with this question.
Hi Clifford, Your description (from the comments above) will only happen if the second 10 numbers are an exact copy of the first 10 numbers. Think of it this way:
Imagine your first 10 random numbers add up to 10. Numbers 2:11 have simply dropped the first number and added the 11th number. If the sum of these must also add up to 10, this will only happen if i(11)==i(1), and then i(12)==i(2) for the next set, etc.
That being said, here's how I would do it:
% Make the first 10 random numbers randSet = rand(10,1);
% Force them (by scaling) to add up to 10 randSet = randSet * (10/sum(randSet));
% Turn them into 20 numbers (by copying, as per my description above) finalRandSet = [randSet; randSet];
% See that all windows of 10 adjacent numbers equal 10 sum(finalRandSet(1:10)) sum(finalRandSet(5:14)) sum(finalRandSet(9:18))
Did this help you out Clifford?