]> gitweb.michael.orlitzky.com - octave.git/blobdiff - legendre_p.m
Add ellipses to multi-line function definition.
[octave.git] / legendre_p.m
index 6238929eb2e4aea13ea1cc1548b82dcc59fdb301..36f67617a453124d1b3992aa7d6f45298333dc98 100644 (file)
@@ -1,27 +1,27 @@
 function P = legendre_p(n)
-  ## Return the nth legendre polynomial.
-  ##
-  ## INPUTS:
-  ##
-  ##   * ``n`` - The index of the polynomial that we want.
-  ##
-  ## OUTPUTS:
-  ##
-  ##   * ``P`` - A polynomial function of one argument.
-  ##
+  % Return the `n`th Legendre polynomial.
+  %
+  % INPUT:
+  %
+  %   * ``n`` - The index of the polynomial that we want.
+  %
+  % OUTPUT:
+  %
+  %   * ``P`` - A polynomial function of one argument.
+  %
   if (n < 0)
-    ## Can't do anything here. Return nothing.
+    % Can't do anything here. Return nothing.
     P = NA;
   elseif (n == 0)
-    ## One of our base cases.
-    P = @(x) 1
+    % One of our base cases.
+    P = @(x) 1;
   elseif (n == 1)
-    ## The second base case.
-    P = @(x) x
+    % The second base case.
+    P = @(x) x;
   else
-    ## Compute recursively.
-    prev = legendre_p(n-1)
-    prev_prev = legendre_p(n-2)
-    P = @(x) (1/n)*( (2*n - 1)*prev(x) - (n-1)*prev_prev(x) )
+    % Not one of the base cases, so use the recursive formula.
+    prev = legendre_p(n-1);
+    prev_prev = legendre_p(n-2);
+    P = @(x) (1/n).*( (2*n - 1).*x.*prev(x) - (n-1).*prev_prev(x) );
   end
 end