]> gitweb.michael.orlitzky.com - octave.git/commitdiff
Add the is_upper_triangular() function and its tests.
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 25 Feb 2013 14:35:00 +0000 (09:35 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 25 Feb 2013 14:35:00 +0000 (09:35 -0500)
is_upper_triangular.m [new file with mode: 0644]
tests/is_upper_triangular_tests.m [new file with mode: 0644]

diff --git a/is_upper_triangular.m b/is_upper_triangular.m
new file mode 100644 (file)
index 0000000..b78991d
--- /dev/null
@@ -0,0 +1,4 @@
+function isUT = is_upper_triangular(A)
+  ## Returns true if ``A`` is upper triangular, false otherwise.
+  isUT = isequal(A, triu(A));
+end
diff --git a/tests/is_upper_triangular_tests.m b/tests/is_upper_triangular_tests.m
new file mode 100644 (file)
index 0000000..209edde
--- /dev/null
@@ -0,0 +1,16 @@
+A = eye(5);
+unit_test_equals("eye(5) is upper-triangular", ...
+                true, ...
+                is_upper_triangular(A));
+
+A = [1, 2, 3; ...
+     0, 4, 5; ...
+     0, 0, 6];
+unit_test_equals("An upper-triangular matrix is upper-triangular", ...
+                true, ...
+                is_upper_triangular(A));
+
+
+unit_test_equals("A lower-triangular matrix is not upper-triangular", ...
+                false, ...
+                is_upper_triangular(A'));