(*  legendre_associated_values.nb *)
(* *)
(*  Purpose: *)
(*    Evaluate the associated Legendre *)
(*    function at selected argument values, *)
(*    and write the data to a file. *)
(* *)
(*  Modified:  29 January 2006 *)
(*  Author:  John Burkardt *)

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

Do [ { n=nvec[[i]], m=mvec[[i]],x=xvec[[i]], f = LegendreP[n,m,x] ,
fvec = Append [ fvec, f ],
      Print["P[",n,",",m,",",x,"]=",N[f,16]] },{i,1,num,1}]

fileout=OpenWrite["C:\\Documents and Settings\\burkardt\\Desktop\\Misc\\mathematica\\legendre_associated_values.txt"];
SetOptions[fileout,FormatType->TextForm];
Write[fileout,"#  legendre_associated_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];