divide list of numbers into 5 groups in matlab - matlab-guide

I have a list of numbers,[1:20],that I need to divide five groups. This division can be randomly or other kind of classification. Any ideas of how to do this in matlab?

Related

Algorithm to find number of ways to group balls of different colours

I have this problem that I'm stuck at for quite some time.
We are given n balls (edit: in a line) that we want to put into different groups. Each ball has a
color denoted by an integer. Two groupings are considered different if there are two
balls in the same group in one grouping but not in the other grouping.
Find the number of ways to group the balls such that the number of colors represented in each group is between two integers a and b (ie. a <= number of colors <= b).
Edit: The groupings are such that whenever we want to split the balls into separate groups, it must occur along the line.
So if we want to split balls of colours 1,2,3,3,4,1,3 into groups and a=2, b=3, then the groupings are 1,2 | 3,3,4 | 1,3, 1,2,3 | 3,4 | 1,3.
I'm stuck at trying to come up with a dynamic programming solution to this. One solution I thought about was to consider what happens when we have the number of groupings for k - 1 balls and to see how many groups we can put k balls into – so we keep adding balls to existing groups until we have enough balls of different color above the min number of colors requirement to create a new group. But I realized there are a lot of ways to do this and am not sure whether this is a viable direction. Any ideas?
In the original version of the question, all colours were different.
Then a simple solution would have been:
X(n) = sum_{k=a to b} X(n-k)
with memoization to avoid performing same calculation at different times.
As the balls can have a different colour, from a given starting point, we have to count the number of different colours from this starting point. This can be achieved by inserting the colours in a set (or a hash-set) and checking the size of this set.
In this case, for the recursion, we can use the index of the stating point
X(index) = sum _{k = ...} X(index + k)
when the range of k is controlled by the number of different colours from the index.
The final result is equal to X(0).

Compare two lists of distances (floats) in python

I'm looking to compare two lists of distances (floats) in python. The distances represent how far away my robot is from a wall at different angles. One array is my "best guess" distance array and the other is the array of actual distances. I need to return a number between [0, 1] that represents the similarity between these two lists of floats. The distances match up 1 to 1. That is, the distance at index 0 should be compared to the distance at index 0 in the other array. Right now, for each index, I am dividing the smaller number by the larger number to get a percentage difference. Then I am taking the average of these percentage differences (total percentage difference / number of entries in the array) to get a number between 0 and 1. However, my approach does not seem to be accurate enough. Is there a better algorithm for comparing two ordered lists of floats?
It looks like you need a normalized Euclidean distance between two vectors.
It is simple to caclulate and you can read more about it here.

A good starting number for the middle square method

I want to generate using the middle square method 10,000 (ten thousand) numbers with 6 decimals for both higher than 1 (for example 785633)and lower than 1(for example 0.434367) starting numbers. Is there any starting number for the two situations that can generate 10,000 distinct numbers?
You generally want a pretty big number for middle-square, say fifty digits or so. When you pick six digits (they can be any portion of the middle part of the number), you can use them as a six-digit number or divide by a million and use them as a decimal number.
You should be aware that middle-square is no longer considered a good method for generating random numbers. A simple linear congruential generator is faster and better, and there are many other types of random number generators also.

Does adding random numbers make them more random?

This is a purely theoretical question.
We all know that most, if not all, random-number generators actually only generate pseudo-random numbers.
Let's say I want a random number from 10 to 20. I can do this as follows (myRandomNumber being an integer-type variable):
myRandomNumber = rand(10, 20);
However, if I execute this statement:
myRandomNumber = rand(5, 10) + rand(5, 10);
Is this method more random?
No.
The randomness is not cumulative. The rand() function uses a uniform distribution between your two defined endpoints.
Adding two uniformly distributions invalidates the uniform distribution. It will make a strange looking pyramid, with the most probability tending toward the center. This is because of accumulation of the probability density function with increasing degrees of freedom.
I urge you to read this:
Uniform Distribution
and this:
Convolution
Pay special attention to what happens with the two uniform distributions on the top right of the screen.
You can prove this to yourself by writing to a file all the sums and then plotting in excel. Make sure you give yourself a large enough sample size. 25000 should be sufficient.
The best way to understand this is by considering the popular fair ground game "Lucky Seven".
If we roll a six sided die, we know that the probability of obtaining any of the six numbers is the same - 1/6.
What if we roll two dice and add the numbers that appear on the two ?
The sum can range from 2 ( both dice show 'one') uptil 12 (both dice show 'six')
The probabilities of obtaining different numbers from 2 to 12 are no longer uniform. The probability of obtaining a 'seven' is the highest. There can be a 1+6, a 6+1, a 2+5, a 5+2, a 3+4 and a 4+3. Six ways of obtaining a 'seven' out of 36 possibilities.
If we plot the distribution we get a pyramid. The probabilities would be 1,2,3,4,5,6,5,4,3,2,1 (of course each of these has to be divided by 36).
The pyramidal figure (and the probability distribution) of the sum can be obtained by 'convolution.
If we know the 'expected value' and standard deviation ('sigma') for the two random numbers, we can perform a quick a ready calculation of the expected value of the sum of the two random numbers.
The expected value is simply the addition of the two individual expected values.
The sigma is obtained by applying the "pythagoras theorem" on the two individual sigmas (square root of the sum of the square of each sigma).

random number with ratio 1:2

I have to generate two random sets of matrices
Each containing 3 digit numbers ranging from 2 - 10
like that
matrix 1: 994,878,129,121
matrix 2: 272,794,378,212
the numbers in both matrices have to be greater then 100 and less then 999
BUT
the mean for both matrices has to be in the ratio of 1:2 or 2:3 what ever constraint the user inputs
my math skills are kind of limited so any ideas how do i make this happen?
In order to do this, you have to know how many numbers are in each list. I'm assuming from your example that there are four numbers in each.
Fill the first list with four random numbers.
Calculate the mean of the first list.
Multiply the mean by 2 or by 3/2, whichever the user input. This is the required mean of the second list.
Multiply by 4. This is the required total of the second list.
Generate 3 random numbers.
Subtract the total of the three numbers in step 5 from the total in step 4. This is the fourth number for the second list.
If the number in step 6 is not in the correct range, start over from step 5.
Note that the last number in the second list is not truly random, since it's based on the other values in the list.
You have a set of random numbers, s1.
s1= [ random.randint(100,999) for i in range(n) ]
For some other set, s2, to have a different mean it's simply got to have a different range. Either you select values randomly from a different range, or you filter random values to get a different range.
No matter how many random numbers you select from the range 100 to 999, the mean is always just about 550. The odds of being a different value are exactly the normal distribution probabilities on either side of the mean.
You can't have a radically different mean with values selected from the same range.

Resources