Ask Your Question
0

solving a set of equations involving both inequalities and equalities

asked 2013-05-03 04:59:25 +0100

REKHA BISWAL gravatar image

updated 2013-05-03 05:03:39 +0100

How to write a code in sage to find solutions of a set of equalities and inequalities in more than one variables.for example i want to find solutions for the equations $\sum_{1 \leq i \leq 3}x_i =10$ , x_1 < x_2 < x_3 .

edit retag flag offensive close merge delete

Comments

Your commentary below seems to indicate that this question needs some serious clarification/correction.

rickhg12hs gravatar imagerickhg12hs ( 2013-05-04 17:48:05 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-05-03 12:46:19 +0100

Volker Braun gravatar image

updated 2013-05-04 07:39:01 +0100

Since everything is linear your solution set is a polyhedron. For simplicity, lets take it closed (use <= instead of <). Then:

sage: P = Polyhedron(eqns=[(-10,1,1,1)], ieqs=[(0,-1,1,0), (0,0,-1,1)])
sage: P.Hrepresentation()
(An equation (1, 1, 1) x - 10 == 0,
 An inequality (-1, 1, 0) x + 0 >= 0,
 An inequality (-1, -2, 0) x + 10 >= 0)

Edit: Lattice points with all variables being positive as well (which is probably what the question is about)

sage: P = Polyhedron(eqns=[(-10,1,1,1)], ieqs=[(0,-1,1,0), (0,0,-1,1), (0,1,0,0)])
sage: P.Hrepresentation()
(An equation (1, 1, 1) x - 10 == 0,
 An inequality (-1, 1, 0) x + 0 >= 0,
 An inequality (-1, -2, 0) x + 10 >= 0,
 An inequality (1, 0, 0) x + 0 >= 0)
sage: P.integral_points()
((0, 0, 10),
 (0, 1, 9),
 (0, 2, 8),
 (0, 3, 7),
 (0, 4, 6),
 (0, 5, 5),
 (1, 1, 8),
 (1, 2, 7),
 (1, 3, 6),
 (1, 4, 5),
 (2, 2, 6),
 (2, 3, 5),
 (2, 4, 4),
 (3, 3, 4))
edit flag offensive delete link more

Comments

Is there any way to define polyhedron in terms of equations rather than points since the number of equations and number of variables might be too large in which case it would not be possible to write all equations in terms of tuples.?

REKHA BISWAL gravatar imageREKHA BISWAL ( 2013-05-04 04:34:54 +0100 )edit
0

answered 2013-05-04 05:15:56 +0100

rickhg12hs gravatar image

Using your example:

sage: var('x_1 x_2 x_3')
(x_1, x_2, x_3)
sage: solve([x_1+x_2+x_3==10, x_1 < x_2, x_2 < x_3], x_1, x_2, x_3)
[[x_1 == -x_2 - x_3 + 10, -1/2*x_3 + 5 < x_2, x_2 < x_3, (10/3) < x_3]]
edit flag offensive delete link more

Comments

I want solutions in terms of tuples of integers not in terms of same equations in different form.

REKHA BISWAL gravatar imageREKHA BISWAL ( 2013-05-04 05:28:41 +0100 )edit
1

You didn't mention in your original question that you want integer solutions (and probably only positive integer solutions). In general, the solution given by solve is not "in terms of the same equations". It is giving you general solutions where the solutions for x1 and x2 depend on the value x3 takes. For *positive* integer solutions what you really want is partitions of 10. Then use the [Partitions class](http://www.sagemath.org/doc/reference/combinat/sage/combinat/partition.html) in Sage. After you get the solutions, eliminate those solutions that have repeated values in them. Alternatively, use the arguments in the `Partitions` command itself to impose such strict monotonicity properties.

ppurka gravatar imageppurka ( 2013-05-04 06:02:59 +0100 )edit

sorry for the inconvenience.Actually i want to find all the lattice points of the polytope given by 20 equations.since i can not write all those 20 equations,hence i wanted to know if there is any code with which i can write equations in stead of tuples.

REKHA BISWAL gravatar imageREKHA BISWAL ( 2013-05-04 07:17:57 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-05-03 04:59:25 +0100

Seen: 1,156 times

Last updated: May 04 '13