Aaron, Thanks for your response! I did find a detour by using juse lambda (not taking sqrt). Appreciate your help!
Shawn On Tuesday, February 3, 2015 at 7:26:35 PM UTC-5, Aaron Meurer wrote: > > You've discovered that SymPy is really bad at dealing with algebraic > expressions. I would recommend just sticking to what you did the first > time, instead of dealing with sqrt(lambda), just use lambda. > > By the way, I don't think simplify() uses the new assumptions. You have to > literally use refine() if you want to simplify things with them. > > Aaron Meurer > > On Mon, Feb 2, 2015 at 9:52 PM, Yuxiang Wang <wangyux...@gmail.com > <javascript:>> wrote: > >> Hi Aaron, >> >> Thank you for your response! >> >> 1) You are right that it is a bug. If I do this: >> >> from sympy import symbols, sqrt, simplify, Matrix, Q >> from sympy.assumptions.assume import global_assumptions >> >> b11, b22, b33, b12, b13, b23 = symbols('b11, b22, b33, b12, b13, b23', >> real=True) >> b = Matrix([[b11, b12, b13], [b12, b22, b23], [b13, b23, b33]]) >> lambda1sq, lambda2sq, lambda3sq = b.eigenvals() >> >> Then an error would pop up. Instead, if I do this: >> >> from sympy import symbols, sqrt, simplify, Matrix, Q >> from sympy.assumptions.assume import global_assumptions >> >> b11, b22, b33, b12, b13, b23 = symbols('b11, b22, b33, b12, b13, b23') >> b = Matrix([[b11, b12, b13], [b12, b22, b23], [b13, b23, b33]]) >> for elem in b: >> global_assumptions.add(Q.real(elem)) >> lambda1sq, lambda2sq, lambda3sq = b.eigenvals() >> >> It would calculate alright. >> >> >> 2) I still have a problem, as can be viewed more clearly on here: >> >> >> http://nbviewer.ipython.org/github/yw5aj/ipynb/blob/master/SymbolicOgden.ipynb >> >> A brief description is - the sqrt(matrix determinant) is not equal to the >> product of the eigenvalues of matrix**(1/2). >> >> Could you please help a little bit in there...? Would what I am doing >> even be mathematically correct? >> >> Thanks! >> >> Shawn >> >> On Monday, February 2, 2015 at 2:49:19 PM UTC-5, Aaron Meurer wrote: >>> >>> >>> >>> On Mon, Feb 2, 2015 at 1:14 PM, Yuxiang Wang <wangyux...@gmail.com> >>> wrote: >>> >>>> Dear all, >>>> >>>> I am currently trying to do solid mechanics (finite deformation) in >>>> SymPy. There are a lot of matrices that are positive definite, but I do >>>> not >>>> know whether there is a way to define this property in SymPy. Any help >>>> would be deeply appreciated! >>>> >>>> Take this code snippet for example: >>>> >>>> >>>> ``` >>>> from sympy import symbols, init_printing, sqrt, simplify, Matrix >>>> init_printing() >>>> >>>> # Define a positive-definite real symmetric matrix >>>> b11, b22, b33, b12, b13, b23 = symbols('b11, b22, b33, b12, b13, b23') >>>> b = Matrix([[b11, b12, b13], [b12, b22, b23], [b13, b23, b33]]) >>>> >>>> J = sqrt(b.det()) >>>> lambda1sq, lambda2sq, lambda3sq = b.eigenvals() >>>> lambda1, lambda2, lambda3 = sqrt(lambda1sq), sqrt(lambda2sq), >>>> sqrt(lambda3sq) >>>> >>>> simplify(lambda1 * lambda2 * lambda3 - J) >>>> ``` >>>> >>>> 1) Supposedly, the result of the simplify() should be zero. However it >>>> is not, because we are not sure whether the eigenvalues of the matrix b >>>> are >>>> positive! They are because the matrix should be positive definite, but I >>>> do >>>> not know how to define that. >>>> >>> >>> Maybe refine(lambda1, Q.positive(lambda1sq)). >>> >>> >>>> >>>> 2) Also, I know that I could've used real=True in where I defined the >>>> symbols of b11, b22, b33.... But I didn't do that. The reason is, if I use >>>> real=True, then I cannot get the eigenvalues any more - it will say >>>> >>>> TypeError: cannot determine truth value of-b11*b22*b33 + b11*b23**2 + >>>> b12**2*b33 - 2*b12*b13*b23 + b13**2*b22 + 2*(-b11 - b22 - b33)**3/27 - >>>> (-b11 - b22 - b33)*(b11*b22 + b11*b33 - b12**2 - b13**2 + b22*b33 - >>>> b23**2)/3 < 0 >>>> >>> >>> This error almost always indicates a bug. >>> >>> Aaron Meurer >>> >>> >>>> >>>> Any way to tighten that up as well? >>>> >>>> Thanks, >>>> >>>> Shawn >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "sympy" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to sympy+un...@googlegroups.com. >>>> To post to this group, send email to sy...@googlegroups.com. >>>> Visit this group at http://groups.google.com/group/sympy. >>>> To view this discussion on the web visit https://groups.google.com/d/ >>>> msgid/sympy/02b195fa-d0ef-4523-95fb-059599803090%40googlegroups.com >>>> <https://groups.google.com/d/msgid/sympy/02b195fa-d0ef-4523-95fb-059599803090%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sympy+un...@googlegroups.com <javascript:>. >> To post to this group, send email to sy...@googlegroups.com <javascript:> >> . >> Visit this group at http://groups.google.com/group/sympy. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sympy/182edef1-c430-46f2-b1a1-d92ac343f781%40googlegroups.com >> >> <https://groups.google.com/d/msgid/sympy/182edef1-c430-46f2-b1a1-d92ac343f781%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/1d8a2546-c1bd-4a9d-a573-9a3f0c023ed8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.