I found *asmeurer <https://github.com/asmeurer>* comment here: 
http://stackoverflow.com/questions/27872250/plus-minus-operator-for-python 
<http://stackoverflow.com/questions/27872250/plus-minus-operator-for-python-%C2%B1?newreg=30588109db764915ac50e0d3ef492569>
.
It`s very useful but I`m still stacked:
from sympy import *

pm = Symbol(u'±') # The u is not needed in Python 3. I used ± just for 
pretty printing purposes. It has no special meaning.


k = 0
l = 0
m = 0


f1 = 1; f2 = 2; f3 = 3
# expr = k*f1 + pm*f2 + pm*f3
# expr1 = k*f1; expr2 = l*f2; expr3 = m*f3
# expr = expr1 + pm*expr2 + pm*expr3

expr1list = []


# expr2pos = expr2.subs(pm, 1)
# expr2neg = expr2.subs(pm, -1)
# expr2list = []
# expr2list.append(expr1.subs(pm, 1))
# expr2list.append(expr1.subs(pm, -1))
# 
# expr3pos = expr3.subs(pm, 1)
# expr3neg = expr3.subs(pm, -1)
# expr3list = []
# expr3list.append(expr1.subs(pm, 1))
# expr3list.append(expr1.subs(pm, -1))

for k in range(0,3):
    for l in range(0,3):
        for m in range(0,3):
            if k+l+m == 3: 
                expr1 = k*f1; expr2 = l*f2#; expr3 = m*f3
                expr = expr1 + pm*expr2
                    
                expr1pos = expr.subs(pm, 1)
                expr1neg = expr.subs(pm, -1)
                    
                expr1list.append(expr.subs(pm, 1))
                expr1list.append(expr.subs(pm, -1))
                    
                for p1 in expr1list:

                    print (k,l,m)
                    print expr1list
                    print expr
                    print 'next triple'

gives a lot of errors. The last this one: UnicodeEncodeError: 'ascii' codec 
can't encode character u'\xb1' in position 0: ordinal not in range(128).
But if I try *asmeurer <https://github.com/asmeurer>*`s example from the 
link above it works fine.
Could anybody help for the newbe?


понедельник, 4 апреля 2016 г., 16:32:53 UTC+3 пользователь Dos18i2-se 
Beaverov написал:
>
> Hi, I would like to calculate equations like this: 
>
> z = part1 (+/-) part2 (+/-) part3 ... (+/-) partN.
>
> In case of 3 parts it`s rather easy to code all variants of equations (z1 
> = part1 + part2 + part3; z2 = part1 + part2 - part3; z3 = part1 - part2 - 
> part3; z4 = part1 - part2 + part3). But in case of four or higher numbers 
> of equation parts it seems borring. 
> Can I use sympy for this task? Could you please give some simple example 
> or some key words for search in the google?
> Thanks in advance.
>

-- 
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 https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/527cfae8-5b1f-422d-8c32-cd11d57d5f79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to