Skip to content

Commit 9fd44ba

Browse files
committed
add determinant method
numpy.linalg.det breaks with symbolic data
1 parent 49c1f0a commit 9fd44ba

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

‎spatialmath/base/symbolic.py‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def simplify(x):
229229
"""
230230
Symbolic simplification
231231
232-
:param x: expression to simplofy
232+
:param x: expression to simplify
233233
:type x: symbolic
234234
:return: -1
235235
:rtype: symbolic
@@ -249,3 +249,26 @@ def simplify(x):
249249
else:
250250
return x
251251

252+
def det(x):
253+
"""
254+
Symbolic determinant
255+
256+
:param m: matrix
257+
:type x: ndarray with symbolic elements
258+
:return: determinant
259+
:rtype: ndarray with symbolic elements
260+
261+
.. runblock:: pycon
262+
263+
>>> from spatialmath.base.symbolic import *
264+
>>> from spatialmath.base import rot2
265+
>>> theta = symbol('theta')
266+
>>> R = rot2(theta)
267+
>>> print(R)
268+
>>> print(det(R))
269+
>>> simplify(print(det(R)))
270+
271+
.. note:: Converts to a SymPy ``Matrix`` and then back again.
272+
"""
273+
274+
return sympy.Matrix(x).det()

0 commit comments

Comments
 (0)