Hi barebones,

> I've been using sympy to solve some homework problems that tend to be
> a bit cumbersome on a calculator, and I have to say thanks alot, it's
> really an awesome project. Tonight, I was working on some linear

Awesome, thanks for trying SymPy!

> algebra for a mechanical vibrations problem and I ran into a issue
> with simplify. I have a "calculator" program I was using that looks
> like this:
>
> from sympy import *
> from sympy.matrices import Matrix
>
> Basic.set_repr_level(2)
>
> k,m,w,f = symbols('kmwf')
>
> A = Matrix([[2*k-m*w**2, -k],[-k,k-m*w**2]])
>
> A = A.inv()
>
> B = Matrix([0,f])
> C = A*B
> pprint C

Here is how you can do the same more easily:

$ bin/isympy
Python 2.4.4 console for SymPy 0.5.8-hg. These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z = symbols('xyz')
>>> k, m, n = symbols('kmn', integer=True)
>>> f = Function("f")
>>> Basic.set_repr_level(2)     # pretty print output; Use "1" for python output
>>> pprint_try_use_unicode()    # use unicode pretty print when available


In [1]: k,m,w,f = symbols('kmwf')

In [2]: A = Matrix([[2*k-m*w**2, -k],[-k,k-m*w**2]])

In [3]: A = A.inv()

In [4]: B = Matrix([0,f])

In [5]: C = A*B

In [6]: C
Out[6]:
                f*k
────────────────────────────────────
             ⎛                2    ⎞
⎛         2⎞ ⎜       2       k     ⎟
⎝2*k - m*w ⎠*⎜k - m*w  - ──────────⎟
             ⎜                    2⎟
             ⎝           2*k - m*w ⎠
          f
─────────────────────
                2
       2       k
k - m*w  - ──────────
                    2
           2*k - m*w


> This yields a correct answer, but it is in an unsimplified form. To
> try and simplify one of the elements into something more manageable I
> tried using:
>
> pprint( simplify(c[1]))
>
> This works and gives the simplified answer that I confirmed with
> matlab, but it takes a very long time to compute. Matlab did the
> simplification almost instantly while my TI-89 took about 10 seconds
> and sympy took close to a minute to compute the answer. When I tried

In [7]: simplify(C[1])
Out[7]:
      ⎛          2⎞
   -f*⎝-2*k + m*w ⎠
─────────────────────
 2    2  4          2
k  + m *w  - 3*k*m*w


Indeed this takes a lot of time for me too.

> to simplify the first element in the matrix, I killed the program
> after it had run for 5 minutes and didn't give an answer.
>
> Is this slowness just because of this specific situation, or is it in
> the simplify() method itself? If it's just a problem with my usage,

If you type:

In [8]: simplify??

and enter, you will get the source code of the function, together with
a docstring, you can read there how it works.

Basically, it just tries some "simplifications", but as you can see,
it's far from optimal. However, my bet is, that
the sloweness could be in the factor() function. If that is the case,
we have a high priority issue already:

http://code.google.com/p/sympy/issues/detail?id=474

Basically, factor() for simple expressions should be instant, only for
the complicated ones it should use the (slow) algorithm.

> some tips on how to do this more effectively would be much

You need to first determine, where exactly is spent 90% of time - my
bet is the factor() thing.

> appreciated. If it's a problem with simplify itself, does anybody have
> an idea what might be causing it? I'd love to try and take a look at
> the source code and to try and speed it up, but I'm not sure where to
> start.

Use profiler or printing statemens to determine, what is slowing
things down. Report it back here and we'll think what to do next.
If it's the factor() thing, let's fix the issue above to speed
factor() up for simple expressions. Some ideas how to do that are in
the issue.
If you need more help, just ask. If you find it too difficult, I'll
try to fix it soon. But currently I am concentrating on:

http://code.google.com/p/sympy/issues/detail?id=490

Ondrej



>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to