(*  truncated_normal_ab_moment_values.nb *)
(* *)
(*  Purpose: *)
(*    Evaluate moments of the Truncated Normal AB CDF *)
(*    at selected argument values, *)
(*    and write the data to a file. *)
(* *)
(*  Modified:  14 September 2013 *)
(*  Author:  John Burkardt *)

avec={-1, 0, -1, -1,0, 1/2, -2, -4,4 };
bvec={  1, 1,   0,   1,2, 2,         2,   4, 7 };
muvec={0, 0,  0,   0, 1, 0,         0,   0, 5 };
svec={  1, 1,  1,   2, 1, 1,         1,   1, 1/2 };
fvec = {};
num = Length [ avec ];

Do [ {
j = 2,
a=avec[[i]],
b=bvec[[i]],
mu=muvec[[i]], 
s = svec[[i]], 
tdist = TruncatedDistribution[ {a,b},NormalDistribution[mu,s]],f = Moment[tdist,j] ,
fvec = Append [ fvec, f ],
      Print["  TruncatedNormalAB_Moment[",mu,",",s,",",a,",",b,",",j,"]=",N[f,16]] },{i,1,num,1}]

fileout=OpenWrite["/panfs/panasas1/users/jburkardt/public_html/math_src/truncated_normal/truncated_normal_ab_moment_values.txt"];
SetOptions[fileout,FormatType->TextForm];
Write[fileout,"#  truncated_normal_ab_moment_values.txt"];today=DateList[];Write[fileout,"#  Created on ",today];Write[fileout,"#"];
Write[fileout,"#  mu sigma a b j  f"];
Write[fileout,"#"];
j = 2;
Do[{Write[fileout,muvec[[i]],"  ",N[svec[[i]],4], "  ", N[avec[[i]],4],"  ", bvec[[i]], "  ", j, "  ", N[fvec[[i]],16] ]},{i,1,num,1}];Close[fileout];