normalized ALF (Assotiated Legendre Function) *patch*

Ben Abbott bpabbott at mac.com
Sat Feb 9 16:34:00 CST 2008


kruvalig wrote:
>
>
> In matlab enxist function legendre, and it can compute fully  
> normalized
> assotiated function, and normalized by Schmidt. Does exist anything  
> the
> same in octave.
>
> I now that legendre-function in octave can compute un-normalized  
> function.
>
> And i interested in fully normalized ALF
>
>                  (2-delta(0,m))(2n+1)(n-m)!
> P_nm(t) = sqrt(----------------------------) P_nm(t)
>                          (n+m)!

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 <bpabbott at mac.com>

	* 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} {@var{L} =} legendre (@var{n}, @var{X})
+## @deftypefnx {Function File} {@var{L} =} legendre (@var{n},  
@var{X}, "unnorm")
  ##
  ## Legendre Function of degree n and order m
  ## where all values for m = 0.. at var{n} are returned.
@@ -53,19 +54,75 @@
  ## m=3 |  0.00000 | -1.24229 | -3.24000
  ## @end group
  ## @end example
+##
+## @deftypefnx {Function File} {@var{L} =} 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} {@var{L} =} 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 <kai.habel at gmx.de>

-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);
+
+


-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080209/4a0f3164/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: legendre.diff
Type: application/octet-stream
Size: 3542 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080209/4a0f3164/attachment.obj 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080209/4a0f3164/attachment-0001.html 


More information about the Octave-maintainers mailing list