(*  legendre_associated_normalized_values.nb *)
(* *)
(*  Purpose: *)
(*    Evaluate the associated Legendre *)
(*    function at selected argument values, *)
(*    with a particular  normalization, *)
(*    and write the data to a file. *)
(* *)
(*  Modified:  12 March 2012 *)
(*  Author:  John Burkardt *)

nvec={0,
1,1,
2,2,2,
3,3,3,3,
4,4,4,4,4,
5,5,5,5,5,5};
mvec={0,
0,1,
0,1,2,
0,1,2,3,
0,1,2,3,4,
0,1,2,3,4,5};
xvec={
1/2,
1/2,1/2,
1/2,1/2,1/2,
1/2,1/2,1/2,1/2,
1/2,1/2,1/2,1/2,1/2,
1/2,1/2,1/2,1/2,1/2,1/2};
fvec = {};
num = Length [ xvec ];

Do [ { n=nvec[[i]], m=mvec[[i]],x=xvec[[i]], scale = Sqrt[4*Pi*(n+m)!/(2*n+1)/(n-m)!],f = LegendreP[n,m,x]/scale ,
fvec = Append [ fvec, f ],
      Print["Y[",n,",",m,",",x,"]=",N[f,16]] },{i,1,num,1}]

fileout=OpenWrite["/Users/jburkardt/public_html/math_src/test_values/legendre_associated_normalized_sphere_values.txt"];
SetOptions[fileout,FormatType->TextForm];
Write[fileout,"#  legendre_associated_normalized_sphere_values.txt"];today=DateList[];Write[fileout,"#  Created on ",today];Write[fileout,"#"];
Write[fileout,"#  n  m  x  f"];
Write[fileout,"#"];
Do[{n=nvec[[i]];m=mvec[[i]];x=xvec[[i]];f=fvec[[i]];Write[fileout,n,"  ",m,"  ",N[x,16],"  ",N[f,16]]},{i,1,num,1}];Close[fileout];