On Sun, Oct 11, 2009 at 11:33 PM, klmn <kklement...@cells.es> wrote: > > 0) I have recently discovered Sympy to myself and am pleased using it. > It is already rich with many interesting capabilities. Thanks a lot > for it! > > 1) I am trying to solve symbolically an eigen-problem depending on a > small parameter. For my 2x2 matrix this takes couple of hours. For a > 3x3 matrix the eigen-problem becomes an ewig-problem: I have never > managed to wait till the end. > Q1) Is there a way how to simplify the problem by retaining only a few > leading terms in the small parameter expansion? > > 2) I tried to use .series() function for simplifying eigenvalues and > eigenvectors of a 2x2 matrix. It takes very long. In the example below > I would expect an immediate result for the expansion, not several > minutes. It seems I am using Sympy not in the best way. > Q2) How can I better deal with small parameters? Do you have docs/ > examples? > > Thank you in advance! > > Example: ************** > d, na, nb, e, dna, dnb, nanb= symbols('d na nb e dna dnb nanb') > d2, na2, nb2= symbols('d2 na2 nb2', positive=True) > > aaa = d2 + dna*e + dnb*e - (8*d2*dna*e + 8*d2*dnb*e + 4*d2**2 + > e**4*na2**2 + e**4*nb2**2 + 4*e**4*nanb**2 + 8*dna**2*e**2 + > 8*dnb**2*e**2 + 8*d2*nanb*e**2 - 4*dna*nb2*e**3 - 4*dnb*na2*e**3 + > 4*dna*na2*e**3 + 4*dnb*nb2*e**3 + 8*dna*nanb*e**3 + 8*dnb*nanb*e**3 - > 2*na2*nb2*e**4)**(sympify(1)/2)/2 + na2*e**2/2 + nb2*e**2/2 > > aaa.series(e,0,3) > ********** the last command takes several minutes to complete.
SymPy's series function is known to be slow in many cases. It's often faster to use Taylor's formula directly. For your expression this takes less than a second: >>> sum = __builtins__.sum >>> sum(aaa.diff(e,k).subs(e,0)*e**k/factorial(k) for k in range(3)).expand() na2*e**2/2 + nb2*e**2/2 - nanb*e**2 - dna**2*e**2/(2*d2) - dnb**2*e**2/(2*d2) + dna*dnb*e**2/d2 Fredrik --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---