Even more Pythonish, and more direct (no conversions, Sage will take care
of the (hairy !) exact arithmetics)...) :
[s for s in solve([eq1, eq2, eq3],[x, y, z], solution_dict=True) if
all(map(lambda t:bool(t>0), s.values()))]
[{z: 1/200000*sqrt(2496889) - 83/200000,
y: 1/200000*sqrt(2496889) - 83/200000,
x: -1/200000*sqrt(2496889) + 15083/200000}]
HTH,
--
Emmanuel Charpentier
Le vendredi 22 septembre 2017 13:47:39 UTC+2, Emmanuel Charpentier a écrit :
>
> Some may find my first answer a bit Lispish. More Pythonish :
>
> [[s.lhs()==s.rhs().n() for s in S] for S in solve([eq1, eq2, eq3],[x, y,
> z])]
> [[x == 0.0675142263037092, y == 0.00748577369629076, z ==
> 0.00748577369629076],
> [x == 0.0833157736962908, y == -0.00831577369629076, z ==
> -0.00831577369629076]]
>
> HTH,
>
> --
> Emmanuel Charpentier
>
> Le vendredi 22 septembre 2017 13:40:45 UTC+2, Emmanuel Charpentier a
> écrit :
>>
>> what's wrong with :
>>
>> map(lambda S:map(lambda s:s.lhs()==s.rhs().n(), S), solve([eq1, eq2,
>> eq3], [x, y, z]))
>>
>> [[x == 0.0675142263037092, y == 0.00748577369629076, z ==
>> 0.00748577369629076],
>> [x == 0.0833157736962908, y == -0.00831577369629076, z ==
>> -0.00831577369629076]]
>>
>> Which shows that the first solution fulfills your constraints ?
>>
>> HTH,
>>
>> --
>> Emmanuel Charpentier
>>
>> Le jeudi 21 septembre 2017 20:27:43 UTC+2, Natalie Ulrich a écrit :
>>>
>>> I'm using SageMathCell to solve chemical equilibrium problems, so at
>>> least one set of my solutions has to be real and positive.
>>>
>>> Here's my code:
>>>
>>> var('x, y, z')
>>>
>>> xi=0
>>>
>>> yi=0.150/2.0
>>>
>>> zi=0.150/2.0
>>>
>>> K=8.3e-4
>>>
>>> eq1=K == y*z/ x
>>>
>>> eq2=xi+yi==x+y
>>>
>>> eq3=2*xi+2*zi==2*x+2*z
>>>
>>> solve([eq1, eq2, eq3],[x, y, z])
>>>
>>>
>>>
>>> And here are my solutions:
>>>
>>> [[x == -1/200000*sqrt(2496889) + 15083/200000, y ==
>>> 1/200000*sqrt(2496889) - 83/200000, z == 1/200000*sqrt(2496889) -
>>> 83/200000], [x == 1/200000*sqrt(2496889) + 15083/200000, y ==
>>> -1/200000*sqrt(2496889) - 83/200000, z == -1/200000*sqrt(2496889) - 83/
>>> 200000]]
>>> ------------------------------
>>>
>>>
>>> Any thoughts? Thanks in advance.
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"sage-support" 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/sage-support.
For more options, visit https://groups.google.com/d/optout.