]> gitweb.michael.orlitzky.com - octave.git/commitdiff
Add the c_norm function and l2_project functions.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 15 Nov 2012 06:49:44 +0000 (01:49 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 15 Nov 2012 06:49:44 +0000 (01:49 -0500)
Fix legendre_p and legendre_p_tilde to work with vectors.

c_norm.m [new file with mode: 0644]
legendre_p.m
legendre_p_tilde.m

diff --git a/c_norm.m b/c_norm.m
new file mode 100644 (file)
index 0000000..865ff8b
--- /dev/null
+++ b/c_norm.m
@@ -0,0 +1,20 @@
+function c_norm = c_norm(w, a, b, v)
+  ##
+  ## The norm on C[a,b] induced by c_inner_product.
+  ##
+  ## INPUT:
+  ##
+  ##   * ``w`` -- The weight function.
+  ##
+  ##   * ``a`` -- The left endpoint of the interval.
+  ##
+  ##   * ``b`` -- The right endpoint of the interval.
+  ##
+  ##   * ``v`` -- The vector.
+  ##
+  ## OUTPUT:
+  ##
+  ## The norm of `v`; that is, the inner product sqrt(<v, v>).
+  ##
+  c_norm = sqrt(c_inner_product(w, a, b, v, v));
+end
index 6238929eb2e4aea13ea1cc1548b82dcc59fdb301..276e7407d39f2d410dd38439f389891b11993b8d 100644 (file)
@@ -14,14 +14,14 @@ function P = legendre_p(n)
     P = NA;
   elseif (n == 0)
     ## One of our base cases.
     P = NA;
   elseif (n == 0)
     ## One of our base cases.
-    P = @(x) 1
+    P = @(x) 1;
   elseif (n == 1)
     ## The second base case.
   elseif (n == 1)
     ## The second base case.
-    P = @(x) x
+    P = @(x) x;
   else
     ## Compute recursively.
   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
   end
 end
index e5e6f63b39b929731c3c8281f59b4510fbbf494c..0b3a87ba698dc41c560cc0b38c52b4549a8348e8 100644 (file)
@@ -18,7 +18,7 @@ function P_tilde = legendre_p_tilde(n, a, b)
     P = NA;
   else
     ## Compute the Legendre polynomial over [-1,1] and mangle it.
     P = NA;
   else
     ## Compute the Legendre polynomial over [-1,1] and mangle it.
-    P = legendre_p(n)
-    P_tilde = @(x) P( (2/(b-a))*x + 1 - (2*b)/(b-a) )
+    P = legendre_p(n);
+    P_tilde = @(x) P( (2/(b-a)).*x + 1 - (2*b)/(b-a) );
   end
 end
   end
 end