diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2020-05-13 15:17:10 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2020-05-14 10:28:51 +0200 |
commit | 1d559581b3bcd91644e44b1e3a3788614d99924f (patch) | |
tree | 1d50f80af6168494032043f4191b486dc90f62b0 /test | |
parent | a4671733b7b990e83ef6daed4d17ab240a3591b5 (diff) | |
download | emacs-1d559581b3bcd91644e44b1e3a3788614d99924f.tar.gz |
Calc: fix LU decomposition for non-numeric matrices (bug#41223)
Computing determinant and inverse for on some matrices containing
non-numeric elements failed or gave the wrong result.
Reported by Mauro Aranda.
* lisp/calc/calc-mtx.el (math-do-matrix-lud): Don't use zero as pivot.
* test/lisp/calc/calc-tests.el (calc-matrix-determinant): New test.
Diffstat (limited to 'test')
-rw-r--r-- | test/lisp/calc/calc-tests.el | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el index 6db5426ff6d..9e36d91ac3e 100644 --- a/test/lisp/calc/calc-tests.el +++ b/test/lisp/calc/calc-tests.el @@ -345,6 +345,30 @@ An existing calc stack is reused, otherwise a new one is created." (should (Math-num-integerp '(float 1 0))) (should-not (Math-num-integerp nil))) +(ert-deftest calc-matrix-determinant () + (should (equal (calcFunc-det '(vec (vec 3))) + 3)) + (should (equal (calcFunc-det '(vec (vec 2 3) (vec 6 7))) + -4)) + (should (equal (calcFunc-det '(vec (vec 1 2 3) (vec 4 5 7) (vec 9 6 2))) + 15)) + (should (equal (calcFunc-det '(vec (vec 0 5 7 3) + (vec 0 0 2 0) + (vec 1 2 3 4) + (vec 0 0 0 3))) + 30)) + (should (equal (calcFunc-det '(vec (vec (var a var-a)))) + '(var a var-a))) + (should (equal (calcFunc-det '(vec (vec 2 (var a var-a)) + (vec 7 (var a var-a)))) + '(* -5 (var a var-a)))) + (should (equal (calcFunc-det '(vec (vec 1 0 0 0) + (vec 0 1 0 0) + (vec 0 0 0 1) + (vec 0 0 (var a var-a) 0))) + '(neg (var a var-a))))) + + (provide 'calc-tests) ;;; calc-tests.el ends here |