how to compute random??
1 view (last 30 days)
So the questiuon is asking about random numbers and computing them:
Let Sn be the sum of n such random numbers, and let
An be the average these random numbers. Intuitively, An should be closer to 0.5 when n
Write a program that inputs an error tolerance tol, computes the smallest integer ns
such that |Ans −0.5| ≤ tol, then displays ns, Rns, and Ans.
But I don't know how you would compute it? It really confuses me, thanks
tol=input('Enter error tolerance:');
David Hill on 26 Sep 2022
Run a simulation many times below.
for k=1:1000 %I ran the simulation 1000 times
nm=mean(f) %I took the average of the lowest n at which abs(An-.5)<=tol
More Answers (1)
Walter Roberson on 26 Sep 2022
n appears to be your counter. But you are overwriting n with a random number.
You never change A within your while loop so if the loop is entered at all it can never exit.
Rns and ns are not assigned at this point
R is assigned at this point but it is still the initial 0 that it was assigned.
Each time you are generating a new random number you should be adding it to a total, and you should be calculating an average (that should probably be assigned into A)
In terms of your code, what are Rns and Ans intended to mean ?? They are not obvious variable names and there is no documentation for them. Will an output about the value of Rns= be meaningful to readers?
nStar has not been assigned to at this point.