On Fri, Nov 18, 2011 at 6:18 AM, Chris Smith <[email protected]> wrote:
> On Fri, Nov 18, 2011 at 6:27 AM, Aaron Meurer <[email protected]> wrote:
>> On Thu, Nov 17, 2011 at 3:16 PM, Joon Lee <[email protected]> wrote:
>>> I'm trying to solve the 'barnyard' problem with sympy with two
>>> equations for 3 variables (it's underconstrained). I want all
>>> possible solutions to be displayed, possibly by iterating
>>>
>>> There are 20 heads and 56 legs, how many chicken, pigs and spiders are
>>> there?
>>>
>>> chickens = Symbol('chickens')
>>> pigs = Symbol('pigs')
>>> spiders = Symbol('spiders')
>>>
>>> solve([Eq(chickens+pigs+spiders, 20), Eq(2*chickens+4*pigs+8*spiders,
>>> 56)])
>>>
>>> this works, but defines chickens and pigs in terms of spiders.
>
> Yes...and those equations will tell you the range that spiders can have:
>
>>>> solve([Eq(chickens+pigs+spiders, 20), Eq(2*chickens+4*pigs+8*spiders,56)])
> {chickens: 2*spiders + 12, pigs: -3*spiders + 8}
>>>> [solve(k) for k in _.values()]
> [[-6], [8/3]]
>>>> flatten(_)
> [-6, 8/3]
>
> So that is the range that will give positive values for spiders:
> greater than -6 and less then 8/3. And as Aaron pointed out, that
> range contains 0, 1 and 2 as "integer spiders" that will still make
> the other equations work. I don't work with set or interval functions,
> but I bet there is a way to turn that range into the set of integers
> or perhaps to solve those equations as inequalities. But that's sugar.
If we had representations for various standard sets, like Z or R, you
could easily obtain the solution by taking the intersection of the
interval with Z+ U {0}. I just noticed that we don't have an issue
for this, so I created
http://code.google.com/p/sympy/issues/detail?id=2853.
Aaron Meurer
--
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.