How do I find a point in every region defined by a system of linear equations?
I have a system of eight linear equations of the form
Ai.x+Bi.y=0 (i=1..8)
Ai and Bi are numerical values.
If I plot all eight equations on one graph then I get numerous bounded regions defined by three or more of the equations and numerous unbounded regions defined by two or more of the equations.
(It is possible – though unlikely - for two of the solutions to be parallel or collinear. )
My aim is to find one point – any point does - within every bounded region and one in every unbounded region. It is easy to do this by inspection.
However, I need to do this automatically. The system is dynamic so the Ai and Bi values change and I do not know in advance how many regions there are.
I can see that it is straightforward to find all – (8-1)! I think - solutions of pairs of equations (intersecting points) and I can see that it will be possible to write an algorithm to find the regions but before I do two questions:
1) Is there a particular branch of linear programming which deals with this sort of problem?
2) Or even better are there commands in maple to directly deal with this?
Any suggestions most welcome.
Brian
All through the origin?
Two minor comments:
(8-1)! = 5040intersection points between pairs of lines, but onlybinomial(8,2) = 28.LinearUnivariateSystem - very long winded
Thank you on both points
Indeed it should be Ai.x+Bi.y=Ci and indeed 28 intersections.
I have been trying to find a way forward using the LinearUnivariateSystem command. My thinking is that there are 256 solutions.
So if ei (i=1..8) are the LHS of my linear equations (Ai.x+Bi.y-Ci)
eq11111111:={e1>0,e2>0,e3>0,e4>0,e5>0,e6>0,e7>0,e8>0};
then the other 254 equations all the way to
eq00000000:={e1<0,e2<0,e3<0,e4<0,e5<0,e6<0,e7<0,e8<0};
then
LinearUnivariateSystem(eqj,x) (j=11111111..00000000) ought to give as many solutions as there are
But it feels very long winded!
Presently stuck
At present I have coded the following:
5is present to get some interesting plot):giving, for instance,
But I have no clear idea yet as to how to obtain the coordinates of some points inside those regions. Maybe the fact (unless I am fundamentally mistaken) that all bounded regions are convex polygons is helpful: most probably there exist some powerful procedure in such a case. Hopefully, some hardcore mathematician, which I am not, can help us here.
That is exactly the sort of
That is exactly the sort of output I have.
It certainly seems possible to get the definition of every region using LinearUnivariateSystem but so far I cannot see anyway of finding
them without checking all 256 possible solutions and discarding the null ones.
Thank you for your interest.
Bingo
Ah, now I see your strategy: there are
2^8 = 256combinations of being on one or the other sides of the eight lines.Clever! The task at hand now, is then to make Maple do the hard work, that is, programming it efficiently.
Any help?
Is the following of any help?
with(SolveTools:-Inequality): for s1 in {-1,1} do for s2 in {-1,1} do for s3 in {-1,1} do for s4 in {-1,1} do for s5 in {-1,1} do for s6 in {-1,1} do for s7 in {-1,1} do for s8 in {-1,1} do sol := LinearUnivariateSystem({seq(s||i*eqs[i] > 0,i = 1..8)},x); if sol <> {} then print (s1,s2,s3,s4,s5,s6,s7,s8,sol) end if end do: end do: end do: end do: end do: end do: end do: end do:That looks absolutely great.
That looks absolutely great. Thank you so much
Please ignore my other posting - I had not expected further reply
Arrangement of Lines
For what it is worth, the construct you are looking at is called an arrangement of lines in the plane by folks in computational geometry. It seems like some sort of topological sweep should be able to get you what you are looking for.
Sadly, it's been a while since the computational geometry class I had back in grad school or I could help with more than just names of things.
Linear Programming
Suppose L is a list of expressions A[i]*x + B[i]*y - C[i], and S is a subset of {$1..n}. Then applyop(`*`,S,L,-1) multiplies the expressions numbered by members of S by -1. Make each of the results r into an inequality r < 0, and then you can call LinearUnivariateSystem on the result. Thus:
> L := [seq](A[i]*x + B[i]*y - C[i], i=1..8); P:= map( t -> SolveTools[Inequality][LinearUnivariateSystem]( map(`<`, applyop(`*`,t,L,-1), 0), x), combinat[powerset]({$1..8}));But to actually get a point in each region, I think linear programming (LPSolve in the Optimization package) might be better. If a region given by a set of inequalities A[i]*x + B[i]*y - C[i] < 0 is nonempty and bounded, you can find a point in it by maximizing t such that A[i]*x + B[i]*y - C[i] + t <= 0. If the region is unbounded, add a constraint t <= M for some large M (say 10^6; this might have to be adjusted). So I might try something like this:
> getpt:= proc(T) local R, t; R:= convert(map(s -> (s + t <= 0), T),set) union {t <= 10^6}; R:= Optimization[LPSolve](t, R, maximize = true); if R[1] <= 0 then NULL else subs(R[2],[x,y]) fi; end; map(t -> getpt(applyop(`*`,t,L,-1)), combinat[powerset]({$1..8}));And along came Israel, ...
... as always providing delightfully compact code.
If I might just ask for a
If I might just ask for a little more help. I am struggling to understand what is going on in the first section of your code Robert.
I have written it out in a little fuller form
L := [seq](A[i]*x + B[i]*y - C[i], i=1..8):
> CPS:=combinat[powerset]({$1..8}):
> P:= map( t -> ( map(`<`, applyop(`*`,t,L,-1) , 0) ) , CPS);
But that last line is eluding me. In particular the t in the applyop
Thank for all the help so far.
What's going on
If L is a list of length n and t is a set of integers from 1 to n, applyop(`*`, t, L, -1) produces the list whose j'th element is -L[j] if j is in t, L[j] otherwise. In other words, you are applying the multiplication operator `*` with second argument -1 to those operands of L that are in t, while leaving the others alone.
map(`<`, ..., 0) takes this list and transforms each element e to e < 0, so you now have a list of inequalities.
Thus
is a function that takes the set t and returns the list of inequalities (+/-) L[i] < 0, using - for those i in t and + otherwise.
Finally, with CPS a set of sets, the outer "map" applies this function to each member of CPS.
Thank you Robert that is
Thank you Robert that is most helpful.
I have also followed up the issue of number of regions produced by lines on a plane a
and an article can be found on
PlatonicDivisionsofSpace
Maximum number of regions
How many regions are produced by n lines in general position (no two parallel, no three coincident)? Note that the n'th line intersects each of the first n-1 lines in exactly one point, so splits in two exactly n of the regions created by the first n-1 lines. Thus the number of regions is R(n) = R(n-1) + n, with R(1) = 2, leading to
> simplify(rsolve({R(n)=R(n-1)+n, R(1)=2}, R(n)));See also
http://www.research.att.com/~njas/sequences/A000124
Update
For finding a point inside each bounded region, please see my blog post Regions bounded by lines.