X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=legendre_p.m;h=276e7407d39f2d410dd38439f389891b11993b8d;hp=6238929eb2e4aea13ea1cc1548b82dcc59fdb301;hb=79707c807c6f44eb95ec0eeeaa28f7e98bf8c319;hpb=ee06b882dfb9a86788d7057cec8ca6d7680c5ca5 diff --git a/legendre_p.m b/legendre_p.m index 6238929..276e740 100644 --- a/legendre_p.m +++ b/legendre_p.m @@ -14,14 +14,14 @@ function P = legendre_p(n) P = NA; elseif (n == 0) ## One of our base cases. - P = @(x) 1 + P = @(x) 1; elseif (n == 1) ## The second base case. - P = @(x) x + 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) ) + 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