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: Sun, 15 Aug 2010 19:50:04 +0000 (UTC)
Organization: FIU
Lines: 30
Message-ID: <i49gdc$7fj$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>
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 1281901804 7667 172.30.248.35 (15 Aug 2010 19:50:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 15 Aug 2010 19:50:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2433679
Xref: news.mathworks.com comp.soft-sys.matlab:662228

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