Hi,

On Fri, Apr 23, 2010 at 04:16:36PM +0200, Bastian Weber wrote:
> Dear List,
> 
> I just discovered the following (imho unsatisfactory) behavior of
> Matrix.det:
> 
> 
> In <211>: from sympy.abc import a,b,c,d, C
> In <212>: M = Matrix([[a+b, 0, cos(c)], [0, d, 0], [cos(c), 0,  1]])
> In <213>: M
> Out<213>:
> [ a + b, 0, cos(c)]
> [     0, d,      0]
> [cos(c), 0,      1]
> 
> In <214>: M.det()
> Out<214>: d*a**2/(a + b) + d*b**2/(a + b) + 2*a*b*d/(a + b) -
> a*d*cos(c)**2/(a + b) - b*d*cos(c)**2/(a + b)
> 
> 
> I wonder why there are fractions in the result (all the more as in the
> docstring of det_bareis one reads, that the algorihtm "will result in a
> determinant with minimal number of fractions".).
> 

Minimal does not mean none, although there should be written 'minimal
number of levels of nested fractions'.

> The result is correct but it is in a very inconvenient form for further
> processing.
> 

There is cancel(), simplify(), trigsimp() etc. Choose your tool and
simplify the resulting expression given by Matrix.det(). In general
you can't expect that result from a particular function will be in
a form you would like it to be, but you can always use rewrite and
simplification routines to transform an expression to a "better"
form.

Example:

In [24]: cancel(_214)
Out[24]: 
                 2   
a⋅d + b⋅d - d⋅cos (c)

(using git version of SymPy)

> My observation is, that the result of det is better (i.e. as expected)
> if there are no trigonometric terms in the matrix:
> 
> 
> In <215>: M.subs(cos(c), C).det()
> Out<215>: a*d + b*d - d*C**2
> 
> 
> Is that a bug or do I miss something?
> 

> Regards,
> Bastian.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
> 

-- 
Mateusz

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to