From: dhaskantha on 24 Jun 2010 05:10 Oh yes. This one is the recurrence formula for the Poisson pmf. What if I happened to bump into cases such as: for i=1:n x(i)=normrnd(0,1); end where I only want the values of x(i), say between 0 and 1. How do I do it? Thanks.
From: Jan Simon on 24 Jun 2010 06:21 Dear dhaskantha, > for i=1:n > x(i)=normrnd(0,1); > end > > where I only want the values of x(i), say between 0 and 1. How do I do it? Between 0 and 1: x = min(0, max(1, anyFunction)) 0 or 1: x = double(anyFunction > 0.5); Obviously "0.5" is just an example and "anyFunction" depends on your needs. anyFunction can reply (or be) an array also, which is usually faster than using a FOR loop for elementwise processing. Care about NaNs, on demand. Good luck, Jan
From: dhaskantha on 24 Jun 2010 08:07 Thank you, Jan. I will try.
From: Roger Stafford on 24 Jun 2010 12:39 "dhaskantha " <dharen10(a)gmail.com> wrote in message <hvvhpr$5nd$1(a)fred.mathworks.com>... > Thank you, Jan. I will try. - - - - - - - - - Rather than changing values which lie outside of [0,1] to a 0 or 1, from a statistical point of view it is probably preferable to simply reject them and repeat the call on normrnd or whatever your source is until you have a sufficient number of random values. Otherwise you may get a number of values that are artificially stacked up at exactly 0 or 1 and this would skew your statistical distribution. You can accomplish this with a while loop. Always remember that when you truncate a normal distribution in this manner, strictly speaking you no longer have a normal distribution, which is supposed to be free to extend to an unlimited amount either up or down. Both the mean and variance will be different from what you might expect. Roger Stafford
From: dhaskantha on 24 Jun 2010 19:50 Thank you. Roger. Could you show me an example of 20 generating random normal values between 0 and 1 using the while loop? Your help is much appreciated. I am not very familiar with the while loop. Thank you, once again. Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i001n8$8or$1(a)fred.mathworks.com>... > "dhaskantha " <dharen10(a)gmail.com> wrote in message <hvvhpr$5nd$1(a)fred.mathworks.com>... > > Thank you, Jan. I will try. > - - - - - - - - - > Rather than changing values which lie outside of [0,1] to a 0 or 1, from a statistical point of view it is probably preferable to simply reject them and repeat the call on normrnd or whatever your source is until you have a sufficient number of random values. Otherwise you may get a number of values that are artificially stacked up at exactly 0 or 1 and this would skew your statistical distribution. You can accomplish this with a while loop. > > Always remember that when you truncate a normal distribution in this manner, strictly speaking you no longer have a normal distribution, which is supposed to be free to extend to an unlimited amount either up or down. Both the mean and variance will be different from what you might expect. > > Roger Stafford
|
Next
|
Last
Pages: 1 2 Prev: Plotting 3D of a function with circular domain Next: plotting 2-part function |