Adding some changes and code rewriting
Show older comments
[EDIT: 20110628 00:13 CDT - reformat - WDR]
i have code and i would like to make some changes and add 2 conditions for these 3 random variables (c, gama, fi). i want to limit each of them in a specific zone and check the random number which is generated in every loop to not be duplicated also not be out of range.
these are conditions:
- 2.7< fi <16.3
- 450< c <800
- 1.92< gama <1.98
and each of them must be check to not be repeating in every loop.
this is my code :
clear;
clc
B=1000;L=2000;Sc=1.1;Sq=1.1;Sgama=.8;
nsamples=10000;
for i=1:nsamples
C=normrnd(620,147.64);
gama=normrnd(1.96,0.02);
fi=normrnd(3.76,1.1034);
Nq=tan((pi/4)+(pi*fi/360))*tan((pi/4)+(pi*fi/360))*2.718^(pi*tan(fi*pi/180));
Nc=(Nq-1)*cot(fi*pi/180);
Ngama=2*(Nq+1)*tan(fi*pi/180);
qult(i)=(C*Nc*Sc)+(384*Nq*Sq)+(980*Ngama*Sgama);
end
Accepted Answer
More Answers (1)
Krishna Kumar
on 28 Jun 2011
0 votes
To get the random numbers within some limits, you can use randn( since you seem to want random distributed values. x= lowerlimit+(lower limit-upperlimit)*randn(size(array)); For the second question, you must weigh the utility of it against the computational burden it imposes. I suppose randn function does not return exactly equal values so frequently. If at all you want to check the same, you need to store all previous values in an array and check the new value with this each time, which I think does not add value to code. Or you can try some funny ideas like this. random_number= mean(randn(1)+rand(1)). Since both of the random number may not be repeated, chance of repetition are still lower. Or form the random numbers in a single matrix initially,(nsamples,1) sizes vector and check for repetition before entering the loop.
Hope you can fix these things easily.
2 Comments
Walter Roberson
on 28 Jun 2011
The mean() of two random values with the same distribution will have a smaller standard deviation than a single random value of that distribution would have: the values will cluster more to the center.
For example, with six-sided dice, the probability of a "1" being thrown on a single dice is 1/6, but the probability of 1 being the result of the mean of two six-sided dice is only 1 in 36 (both would have to be thrown as 1's for the mean to be 1.)
Krishna Kumar
on 28 Jun 2011
thanks WR for the insight.
Categories
Find more on Multivariate t Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!