On Wed, Aug 26, 2009 at 2:03 AM, brandyn<[email protected]> wrote:
>
> Hi,
>
> Is there a way in sympy to work with symbolic vectors and matrices?
> Or, more specifically and low level, to use "sum" in a purely symbolic
> manner?  E.g.:
>
> Let's say I have two data vectors of large and unknown length, X and
> Y.  I would like to blend them with:
>
> e = sum_i [(a*X_i + (1-a)*Y_i)^2]
>
> Now I would like to compute de/da, set that to zero, and solve.
>
> The solution, I believe, is:
>
> a = sum_i(Y_i*(Y_i - X_i)) / sum_i (X_i-Y_i)^2
>
> But I would like to be able to double-check this with sympy.  (Even if
> sympy can't figure out this solution on its own, it would be quite
> nice if I could walk it through the steps and sympy could just make
> sure I've made no errors.)
>
> This is a very simple example -- consider matrices along with high
> level operators such as diag(), matrix mul, element-wise operations...
> the various things numpy can do, for instance.  But the question is
> how to be able to represent such a thing abstractly in sympy, without
> ever naming the size of the matrices for instance.
>
> Is there a way to do this I just haven't found yet?

If I understand you correctly, you want to be able to work with
expressions with indices? E.g. like tensors etc.?

Currently we can't do it yet, but it's in our issues:

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

as you can see, it's a very old issue. :) Any help with fixing it is
appreciated.

So currently the only way is to define symbols by hand:

In [1]: s = [Symbol("a_%d" % i) for i in range(10)]

In [2]: s
Out[2]: [a₀, a₁, a₂, a₃, a₄, a₅, a₆, a₇, a₈, a₉]

In [3]: Add(*s)
Out[3]: a₀ + a₁ + a₂ + a₃ + a₄ + a₅ + a₆ + a₇ + a₈ + a₉


and use Add to sum them.

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