Approximating Euler's number using randomly generated integers
이전 댓글 표시
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!