Prev: Movie out of .fig files?
Next: Size of Hex Strings
From: Bruno Luong on 2 Aug 2010 17:05 "BobC Cadenza" <bobc(a)mailinator.com> wrote in message <i371ts$ht3$1(a)fred.mathworks.com>... > Given a normal distribution with mu,sigma. How can I find the mean between two points? So for example I want to find the mean value between -.5 *sigma to +2 sigma? > > Thanks Take a look at my FEX submission: http://www.mathworks.com/matlabcentral/fileexchange/23832-truncated-gaussian sigma=2; [trash meaneff sigmaeff]=TruncatedGaussian(-sigma,[-0.5*sigma 2*sigma]); disp(meaneff) % The mean is 0.8915 Bruno
From: BobC Cadenza on 2 Aug 2010 17:22 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i37711$fqu$1(a)fred.mathworks.com>... > "BobC Cadenza" <bobc(a)mailinator.com> wrote in message <i371ts$ht3$1(a)fred.mathworks.com>... > > Given a normal distribution with mu,sigma. How can I find the mean between two points? So for example I want to find the mean value between -.5 *sigma to +2 sigma? > > > > Thanks > - - - - - - - - - - > If p(x) is the pdf of the original normal distribution with mu and sigma from -infinity to +infinity, but you want the mean value of that distribution restricted to some finite range, [a,b], then you can do the following. > > mean value = int(x*p(x),'x',a,b)/int(p(x),'x',a,b) > > The denominator is just the cdf difference between its value at b from that at a. In the case of the numerator you can write > > int(x*p(x),'x',a,b) = int((x-mu)*p(x),'x',a,b) + mu*int(p(x),'x',a,b) > > Since this is the normal distribution, the first of these terms is easy to integrate and gives sigma^2*(p(a)-p(b)), while the second term is again obtained from the difference between cdf's. > > Roger Stafford Thanks Roger, that works perfectly. Since that worked so nice, how about adding in a wrinkle. How would I include in the mean the values, that are outside a and b limited to a and b. For example p(x<a)=p(a) and p(x>b)=p(b)
From: Roger Stafford on 2 Aug 2010 18:39 "BobC Cadenza" <bobc(a)mailinator.com> wrote in message <i37ctu$1ta$1(a)fred.mathworks.com>... > Thanks Roger, that works perfectly. Since that worked so nice, how about adding in a wrinkle. How would I include in the mean the values, that are outside a and b limited to a and b. For example p(x<a)=p(a) and p(x>b)=p(b) - - - - - - - - - - - Well that alters the assumption I was making. When you write int(x*p(x),'x',a,b)/int(p(x),'x',a,b) as I did, that implies that the probability P2(a<=x & x<=b) is one, so that P2(x<a) and P2(x>b) are therefore each equal to zero (where P2 means the revised probability.) In other words, by that former assumption x can't be outside [a,b]. It sounds to me as though you are now saying that the probability density between a and b is to remain that same as in the original normal density, but that all x's below a are now to be concentrated in the single point x=a and similarly for x>b at the point x=b. In that case there is no normalization to be done. The mean would be the straightforward expression: int(a*p(x),'x',-inf,a) + int(x*p(x),'x',a,b) + int(b*p(x),'x',b,inf) where again p(x) is the original pdf for mu and sigma. The first and last of these integrals just involves the cdf for p(x). The middle term is evaluated by the same trick I described earlier. I hope I have understood correctly what you are asking. Roger Stafford
From: BobC Cadenza on 3 Aug 2010 09:08 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i37he8$cmp$1(a)fred.mathworks.com>... > "BobC Cadenza" <bobc(a)mailinator.com> wrote in message <i37ctu$1ta$1(a)fred.mathworks.com>... > > Thanks Roger, that works perfectly. Since that worked so nice, how about adding in a wrinkle. How would I include in the mean the values, that are outside a and b limited to a and b. For example p(x<a)=p(a) and p(x>b)=p(b) > - - - - - - - - - - - > Well that alters the assumption I was making. When you write > > int(x*p(x),'x',a,b)/int(p(x),'x',a,b) > > as I did, that implies that the probability P2(a<=x & x<=b) is one, so that P2(x<a) and P2(x>b) are therefore each equal to zero (where P2 means the revised probability.) In other words, by that former assumption x can't be outside [a,b]. > > It sounds to me as though you are now saying that the probability density between a and b is to remain that same as in the original normal density, but that all x's below a are now to be concentrated in the single point x=a and similarly for x>b at the point x=b. In that case there is no normalization to be done. The mean would be the straightforward expression: > > int(a*p(x),'x',-inf,a) + int(x*p(x),'x',a,b) + int(b*p(x),'x',b,inf) > > where again p(x) is the original pdf for mu and sigma. The first and last of these integrals just involves the cdf for p(x). The middle term is evaluated by the same trick I described earlier. > > I hope I have understood correctly what you are asking. > > Roger Stafford Thanks, This worked perfectly also. I owe you a drink.
From: Roger Stafford on 3 Aug 2010 14:24
"BobC Cadenza" <bobc(a)mailinator.com> wrote in message <i394bk$5c$1(a)fred.mathworks.com>... > Thanks, > This worked perfectly also. I owe you a drink. - - - - - - - - - - You don't owe me anything, BobC. I get pleasure (sometimes) out of answering these questions. The "thanks" are appreciated, however. Roger Stafford |