Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: How can I find the mean between to points of normal distribution? Date: Mon, 16 Aug 2010 00:57:03 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 37 Message-ID: <i4a2cv$86e$1@fred.mathworks.com> References: <i371ts$ht3$1@fred.mathworks.com> <i37711$fqu$1@fred.mathworks.com> <i37ctu$1ta$1@fred.mathworks.com> <i37he8$cmp$1@fred.mathworks.com> <i394bk$5c$1@fred.mathworks.com> <i39ms6$gph$1@fred.mathworks.com> <i49gdc$7fj$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1281920223 8398 172.30.248.35 (16 Aug 2010 00:57:03 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 16 Aug 2010 00:57:03 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:662246 "BobC Cadenza" <bobc@mailinator.com> wrote in message <i49gdc$7fj$1@fred.mathworks.com>... > After my first tests I thought everything was working correctly, but it seems that it is not. I have attached a test script whereas it calculates the expected value with a brute > force way, and a way using the formula you stated in your reply. It calculates these 2 values for varying values of mu. You can see from the plot, that the green line which represents your formula, goes outside the min/max. I probably just have a sign incorrect or > something, so if you could take a look I would really appreciate it. > > function [ ] = testExpectedValue() > > a = 25; > b = 26; > sigma = 1; > > mean1(1) = 0; > mean2(1) = 0; > > for mu=20:.1:30 > > x = random('normal',mu,sigma,1000000,1); > > mean1(end+1) = mean(max(a,min(b,x))); > > mean2(end+1) = a*normcdf(a,mu,sigma) + sigma^2*(normpdf(a)-normpdf(b)) + ... > mu*(normcdf(b,mu,sigma) - normcdf(a,mu,sigma)) + ... > b*(1-normcdf(b,mu,sigma)); > > > end > > close all; > plot(mean1(2:end),20:.1:30);hold on; plot(mean2(2:end),20:.1:30,'g'); > > end - - - - - - - - - - - - I see an error in the term "sigma^2*(normpdf(a)-normpdf(b))" for mean2. You didn't include the mu and sigma arguments. Though the documentation doesn't say, I suspect they default to the standard normal with mu = 0 and sigma = 1 and that would make your result incorrect. In my opinion Mathworks should either state that default in their documentation or else produce an error if the arguments are missing. Roger Stafford