From: Michael Orlitzky Date: Mon, 25 Feb 2013 14:35:00 +0000 (-0500) Subject: Add the is_upper_triangular() function and its tests. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=542e0bbc0bcde79e1366d4280cc0637cd43586d1;p=octave.git Add the is_upper_triangular() function and its tests. --- diff --git a/is_upper_triangular.m b/is_upper_triangular.m new file mode 100644 index 0000000..b78991d --- /dev/null +++ b/is_upper_triangular.m @@ -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 index 0000000..209edde --- /dev/null +++ b/tests/is_upper_triangular_tests.m @@ -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'));