(*  chi_square_noncentral_cdf_values.nb *)
(* *)
(*  Purpose: *)
(*    Evaluate the Chi Square Noncentral CDF *)
(*    at selected argument values, *)
(*    and write the data to a file. *)
(* *)
(*  Modified:  07 January 2006 *)
(*  Author:  John Burkardt *)

Needs["Statistics`ContinuousDistributions`"]

nvec={1,2,3,1,2,3,1,2,3,1,2,3,60,80,100,1,2,3,10,10,10,10,10,10,10,10,10,8}
lambdavec={5/10,5/10,5/10,1,1,1,5,5,5,20,20,20,30,30,30,5,5,5,2,3,4,2,3,4,2,3,4,1/2}
xvec={3,3,3,3,3,3,3,3,3,3,3,3,60,60,60,5/100,5/100,5/100,4,4,4,5,5,5,6,6,6,5}
fvec = {};
num = Length [ xvec ]

Do [ {
n=nvec[[i]], 
lambda = lambdavec[[i]], x=SetPrecision[xvec[[i]],28],
dist=NoncentralChiSquareDistribution[n,lambda],f = CDF[dist,x] ,
fvec = Append [ fvec, f ],
      Print["  NoncentralChiCDF[",n,",",lambda,",",x,"]=",N[f,16]] },{i,1,num,1}]

fileout=OpenWrite["C:\\Documents and Settings\\burkardt\\Desktop\\Misc\\mathematica\\chi_square_noncentral_cdf_values.txt"];
SetOptions[fileout,FormatType->TextForm];
Write[fileout,"#  chi_square_noncentral_cdf_values.txt"];today=DateList[];Write[fileout,"#  Created on ",today];Write[fileout,"#"];
Write[fileout,"#  df  lambda  x  fx"];
Write[fileout,"#"];
Do[{df=nvec[[i]],lambda=lambdavec[[i]],x=xvec[[i]];f=fvec[[i]];Write[fileout,df,"  ",N[lambda,16],"  ",N[x,16],"  ",N[f,16]]},{i,1,num,1}];Close[fileout];