It depends on what you want to do with it, but you can play around
with using Sum and Product. You'll probably need to use something like
Function('x')(i) to represent your indexed symbols.

Aaron Meurer

On Sun, Sep 1, 2013 at 3:27 PM, pdknsk <[email protected]> wrote:
> I have figured out the pattern, and implemented it directly in Python. I
> wonder if there is a more elegant way to implement this with sympy.
>
>>>> var('w w0 w1 x x0 x1 y y0 y1 k')
>>>> solve([Eq(w*w0+x*x0+y*y0, k), Eq(w*w1, x*x1), Eq(w*w1, y*y1)], [w, x,
>>>> y])
>
> Result is this.
>
> w = (k*x1*y1) / w0*x1*y1+w1*x0*y1+w1*x1*y0
> x = (k*w1*y1) / w0*x1*y1+w1*x0*y1+w1*x1*y0
> y = (k*w1*x1) / w0*x1*y1+w1*x0*y1+w1*x1*y0
>
> The pattern is easier to notice when it's expanded, and then rewritten like
> so.
>
> a = w1*x1*y1
> d = a*(w0/w1+x0/x1+/y0/y1)
>
> w = (k*a/w1) / d
> x = (k*a/x1) / d
> y = (k*a/y1) / d
>
> In code.
>
> def f(l, k):
>     import operator
>     a = reduce(operator.mul, operator.itemgetter(1)(l), 1.0)
>     d = sum(a * i[0] / i[1] for i in l)
>     return [(k * a) / (i[1] * d) for i in l]
>
>>>> f([(100, 200), (250, 100), (125, 275), (100, 125)], 500)
> [0.5876068376068376, 1.1752136752136753, 0.42735042735042733,
> 0.94017094017094]
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to