distribution - Inverse Mills Ratio in Matlab -


i trying program in matlab conditional expectation of form:

e[x|a<=x<=b] x~n(u,s^2) (sorry, apparently math editing here isn't used to)

in matlab, have written following code:

y=u+s*(normpdf(a,u,s)-normpdf(b,u,s))/(normcdf(b,u,s)-normcdf(a,u,s)) 

the problem breaks down @ higher values of , b. example, let u=0, s=1, a=10 , b=11. simple logic says answer should between 10 , 11, matlab gives me inf because denominator becomes 0 while numerator 10^-23.

any suggestions make formula give real numbers inputs?

one way numerical integration yourself:

x = linspace(a,b,1000); trapz(x,x.*normpdf(x,u,s)) / trapz(x,normpdf(x,u,s)) 

with example values, gives 10.0981, , pretty fast


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -