|
From: | Ben Abbott |
Subject: | Re: normalized ALF (Assotiated Legendre Function) *patch* |
Date: | Sat, 9 Feb 2008 17:34:00 -0500 |
kruvalig wrote:In matlab enxist function legendre, and it can compute fully normalized I inadvertently deleted the mailing by kruvalig :-( ... so I've forged a reply. I'll try to contact kruvalig as well. In that I've added the normalization options present in Matabs legendre.m to Octave, I've moved this to the maintainers list. 2008-02-09 Ben Abbott <address@hidden> * specfun/cond.m: Added Schmidt semi-normalized and fully normalized legendre functions. I've attached a patch. Ben --- /Users/bpabbott/Development/cvs/octave/scripts/specfun/legendre.m 2007-10-12 17:27:26.000000000 -0400 +++ legendre.m 2008-02-09 17:18:09.000000000 -0500 @@ -18,6 +18,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} address@hidden =} legendre (@var{n}, @var{X}) +## @deftypefnx {Function File} address@hidden =} legendre (@var{n}, @var{X}, "unnorm") ## ## Legendre Function of degree n and order m ## where all values for m = address@hidden are returned. @@ -53,19 +54,75 @@ ## m=3 | 0.00000 | -1.24229 | -3.24000 ## @end group ## @end example +## +## @deftypefnx {Function File} address@hidden =} legendre (@var{n}, @var{X}, "sch") +## +## Computes the Schmidt semi-normalized associated Legendre function. +## The Schmidt semi-normalized associated Legendre function is related +## to the unnormalized Legendre functions by +## +## @example +## For Legendre functions of degree n and order 0 +## +## @group +## 0 0 +## SP (x) = P (x) +## n n +## @end group +## +## For Legendre functions of degree n and order m +## +## @group +## m m m 2(n-m)! 0.5 +## SP (x) = P (x) * (-1) * [-------] +## n n (n+m)! +## @end group +## @end example +## +## @deftypefnx {Function File} address@hidden =} legendre (@var{n}, @var{X}, "norm") +## +## Computes the fully normalized associated Legendre function. +## The fully normalized associated Legendre function is related +## to the unnormalized Legendre functions by +## +## @example +## For Legendre functions of degree n and order m +## +## @group +## m m m (n+0.5)(n-m)! 0.5 +## NP (x) = P (x) * (-1) * [-------------] +## n n (n+m)! +## @end group +## @end example +## ## @end deftypefn -## FIXME Add Schmidt semi-normalized and fully normalized legendre functions - ## Author: Kai Habel <address@hidden> -function L = legendre (n, x) +function L = legendre (n, x, normalization) warning ("legendre is unstable for higher orders"); - if (nargin != 2) + if (nargin < 2 || nargin > 3) print_usage (); endif + if nargin == 3 + switch lower(normalization) + case "sch" + m = 1:n; + scale = (-1).^m .* sqrt (2 * factorial (n-m) ./ factorial (n+m)); + scale = [1, scale]; + case "norm" + m = 0:n; + scale = (-1).^m .* sqrt ((n+0.5) .* factorial (n-m) ./ factorial (n+m)); + case "unnorm" + scale = ones (1, n+1); + otherwise + print_usage (); + endswitch + else + scale = ones (1, n+1); + endif if (! isscalar (n) || n < 0 || n > 255 || n != fix (n)) error ("n must be a integer between 0 and 255]"); @@ -119,6 +176,11 @@ M = kron ((0:n)', ones (1, l)); L = X .^ (M / 2) .* (-1) .^ M .* Y; endif + + if nargin == 3 + scale = scale(:) * ones (1, numel (x)); + L = L .* reshape (scale, size (L)); + endif endfunction %!test @@ -130,3 +192,25 @@ %! 0.00000 -1.24229 -3.24000 %! ]; %! assert(result,expected,1e-5); + +%!test +%! result=legendre(3,[-1.0 -0.9 -0.8], "sch"); +%! expected = [ +%! -1.00000 -0.47250 -0.08000 +%! 0.00000 0.81413 0.80833 +%! -0.00000 -0.33114 -0.55771 +%! 0.00000 0.06547 0.17076 +%! ]; +%! assert(result,expected,1e-5); + +%!test +%! result=legendre(3,[-1.0 -0.9 -0.8], "norm"); +%! expected = [ +%! -1.87083 -0.88397 -0.14967 +%! 0.00000 1.07699 1.06932 +%! -0.00000 -0.43806 -0.73778 +%! 0.00000 0.08661 0.22590 +%! ]; +%! assert(result,expected,1e-5); + + |
legendre.diff
Description: Binary data
[Prev in Thread] | Current Thread | [Next in Thread] |