This is for a problem I've been trying to solve and am stuck on one part of it.
Someone else has posted a question on how to solve this same problem but I am trying to solve it in a different way.
Start by generating K uniform random integers between 1 and K. Compute J, the number of integers between 1 and K, which were never generated. We then approximate the e by the ratio
K/J Eg. K=5 Assume the following integers are randomly generated between 1 and 5. 1 1 2 3 2 Integers 1 2 3 4 5 Number of Instances 2 2 1 0 0 Two integers were never generated (4 and 5) so J =2 Consequently e is approximated by 5/2 = 2.5 Write a function called eapprox that takes the value of K as input, and which then approximates e using the method above. Test your function several times with different values of K. and compare the result to the value of e calculated using the built-in MATLAB function.
So far I have been able to generate the list of random integers using:
k = input('Enter value for k')
x = randi([1,k],1,k)
I am wondering how I can get matlab to go through the random list of integers and find which values were not generated and how many. I suppose it doesn't matter which integers weren't generated, just how many.
I have looked through the basics of indexing available through the help menu in matlab and nothing seems to be relevant to this problem.
Any help would be greatly appreciated.
Best Answer