diff scripts/special-matrix/hilb.m @ 4:b4df021f796c

[project @ 1993-08-08 01:26:08 by jwe] Initial revision
author jwe
date Sun, 08 Aug 1993 01:26:08 +0000
parents
children 16a24e76d6e0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/special-matrix/hilb.m	Sun Aug 08 01:26:08 1993 +0000
@@ -0,0 +1,29 @@
+function retval = hilb (n)
+
+# usage: hilb (n)
+#
+# Return the Hilbert matrix of order n.  The i, j element of a Hilbert
+# matrix is defined as
+#
+#  H (i, j) = 1 / (i + j - 1);
+#
+# See also: hankel, vander, hadamard, invhilb, toeplitz
+
+
+  if (nargin != 1)
+    error ("usage: hilb (n)");
+  endif
+
+  nmax = length (n);
+  if (nmax == 1)
+    retval = zeros (n);
+    for j = 1:n
+      for i = 1:n
+        retval (i, j) = 1 / (i + j - 1);
+      endfor
+    endfor
+  else
+    error ("hilb: expecting scalar argument, found something else");
+  endif
+
+endfunction