//-------------------------------------------------------------- // Legendre polynomials for the L<100 function LegendrePolynomial() { this.Const = new Constants(); this.LMAX = 167; this.PL; this.dPL this.d2PL this.PL_1; this.arrayPL = []; //---------------------------------------------------------- this.fl3 = []; fl3[0]=1.0; var fl=0.0,il; for(il=1;ilthis.LMAX-2) return 0.; if(L<=1) return 0; var l,f1=x,f2=1,ff=0,denom,x2; for(l=2;l<=L;l++) { ff=f1*x; ff=2.*ff-f2-(ff-f2)*this.fl3[l]; if(l!=L) {f2=f1; f1=ff;}// ne delaem v poslednii raz } // polonom this.PL = ff; x2 = x*x; denom = x2-1; if(Math.abs(denom) < this.Const.small_add) denom = this.Const.small_add; denom = 1/denom; // 1-ya proizvodnaya this.dPL = denom*(L*x*ff - L*f1); // 2-ya proizvodnaya denom = L*denom*denom; ff = denom*(ff*(x2*(L-1)-1) + f1*x*(3-2*L) + (L-1)*f2); this.d2PL = ff; return ff; } //------------------------------------------------------------------------------ // Nabor polinomov Legendre dlya l<=L i dannogo znacheniya x=cos(th) this.LegendrePL0ToArray = function(L,x) { if(L>this.LMAX-2) return false; this.arrayPL = []; this.arrayPL[0]=1; if(L==0) return true; this.arrayPL[1]=x; if(L==1) return true; var f,l; for(l=2;l<=L;l++) { f = this.arrayPL[l-1]*x; this.arrayPL[l] = 2.*f-this.arrayPL[l-2]-(f-this.arrayPL[l-2])*this.fl3[l]; } return true; } //------------------------------------------------------------------------------ // L-th Legendre polinom P_L(x) // PL_1 = P_(L-1)(x) - needed for calculation of the P_L derrivative this.Pl0_cos_th = function(L,x) // x=cos(theta) { if(L>this.LMAX-2) return 0.; if(L==0) {this.PL_1 = 0; return 1;} if(L==1) {this.PL_1 = 1; return x;} var l,f1=x,f2=1.,ff=0; for(l=2;l<=L;l++) { ff=f1*x; ff=2.*ff-f2-(ff-f2)*fl3[l]; f2=f1; f1=ff; } this.PL_1 = f2; return ff; } //------------------------------------------------------------------------------ // P_LM(cos(theta)) - Legendre polinom this.Plm_cos_th = function(L,M,cth) // x=cos(theta) { var lplus=L+1, mplus=M+1, lx,m,lt,ltt, fl1,fl2, p1,p2,p3,z, polinom=0, llx=true; if(L>this.LMAX-2) return 0.0; z = Math.abs(1 - cth*cth); z = 0.5*Math.sqrt(z); ltt=lplus; for(m=1;m<=mplus;m++) { lx=m-1; p2=1.0; fl1=lx; if(!llx) for(lt=1;lt<=lx;lt++) { fl1=fl1+1.0; p2=(-p2)*fl1*z; polinom=0; } else llx=false; polinom=p2; p1=0.0; fl2=fl1+1.0; ltt=ltt-1; for(lt=1;lt<=ltt;lt++) { p3=(fl2*cth*p2-fl1*p1)*this.fl3[lt]; fl1=fl1+1.0; fl2=fl2+2.0; polinom=p3; p1=p2; p2=p3; } } if(m%2!=0) return -polinom; else return polinom; } }