Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3231328
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:01:57+00:00 2026-05-17T17:01:57+00:00

I have linear systems of inequalities in 3 variables and I’d like to plot

  • 0

I have linear systems of inequalities in 3 variables and I’d like to plot these regions.
Ideally, I’d like something that looks like objects in PolyhedronData. I tried RegionPlot3D, but the results are visually poor and too polygon-heavy to rotate in real time

Here’s what I mean, the code below generates 10 sets of linear constraints and plots them

randomCons := Module[{},
   hadamard = KroneckerProduct @@ Table[{{1, 1}, {1, -1}}, {3}];
   invHad = Inverse[hadamard];
   vs = Range[8];
   m = mm /@ vs;
   sectionAnchors = Subsets[vs, {1, 7}];
   randomSection := 
    Mean[hadamard[[#]] & /@ #] & /@ 
     Prepend[RandomChoice[sectionAnchors, 3], vs]; {p0, p1, p2, p3} = 
    randomSection;
   section = 
    Thread[m -> 
      p0 + {x, y, z}.Orthogonalize[{p1 - p0, p2 - p0, p3 - p0}]];
   And @@ Thread[invHad.m >= 0 /. section]
   ];
Table[RegionPlot3D @@ {randomCons, {x, -3, 3}, {y, -3, 3}, {z, -3, 
    3}}, {10}]

Any suggestions?

Update: Incorporating suggestions below, here’s the version I ended up using to plot feasible region of a system of linear inequalities

(* Plots feasible region of a linear program in 3 variables, \
specified as cons[[1]]>=0,cons[[2]]>=0,...
Each element of cons must \
be an expression of variables x,y,z only *)

plotFeasible3D[cons_] := 
 Module[{maxVerts = 20, vcons, vertCons, polyCons},
  (* find intersections of all triples of planes and get rid of \
intersections that aren't points *)

  vcons = Thread[# == 0] & /@ Subsets[cons, {3}];
  vcons = Select[vcons, Length[Reduce[#]] == 3 &];
  (* Combine vertex constraints with inequality constraints and find \
up to maxVerts feasible points *)
  vertCons = Or @@ (And @@@ vcons);
  polyCons = And @@ Thread[cons >= 0];
  verts = {x, y, z} /. 
    FindInstance[polyCons && vertCons, {x, y, z}, maxVerts];
  ComputationalGeometry`Methods`ConvexHull3D[verts, 
   Graphics`Mesh`FlatFaces -> False]
  ]

Code for testing

randomCons := Module[{},
   hadamard = KroneckerProduct @@ Table[{{1, 1}, {1, -1}}, {3}];
   invHad = Inverse[hadamard];
   vs = Range[8];
   m = mm /@ vs;
   sectionAnchors = Subsets[vs, {1, 7}];
   randomSection := 
    Mean[hadamard[[#]] & /@ #] & /@ 
     Prepend[RandomChoice[sectionAnchors, 3], vs]; {p0, p1, p2, p3} = 
    randomSection;
   section = 
    Thread[m -> 
      p0 + {x, y, z}.Orthogonalize[{p1 - p0, p2 - p0, p3 - p0}]];
   And @@ Thread[invHad.m >= 0 /. section]
   ];
Table[plotFeasible3D[List @@ randomCons[[All, 1]]], {50}];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:01:58+00:00Added an answer on May 17, 2026 at 5:01 pm

    Here is a small program that seems to do what you want:

    rstatic = randomCons;                    (* Call your function *)
    randeq = rstatic /. x_ >= y_ -> x == y;  (* make a set of plane equations 
                                                replacing the inequalities by == *)
    
    eqset = Subsets[randeq, {3}];            (* Make all possible subsets of 3 planes *)
    
                                             (* Now find the vertex candidates
                                                Solving the sets of three equations *)
    vertexcandidates =      
        Flatten[Table[Solve[eqset[[i]]], {i, Length[eqset]}], 1];
    
                                             (* Now select those candidates 
                                                satisfying all the original equations *)          
    vertex = Union[Select[vertexcandidates, rstatic /. # &]];
    
                                             (* Now use an UNDOCUMENTED Mathematica
                                                function to plot the surface *)
    
    gr1 = ComputationalGeometry`Methods`ConvexHull3D[{x, y, z} /. vertex];
                                             (* Your plot follows *)
    gr2 = RegionPlot3D[rstatic,
            {x, -3, 3}, {y, -3, 3}, {z, -3, 3},
             PerformanceGoal -> "Quality", PlotPoints -> 50]
    
    Show[gr1,gr2]   (*Show both Graphs superposed *)
    

    The result is:

    alt text

    Downside: the undocumented function is not perfect. When the face is not a triangle, it will show a triangulation:

    alt text

    Edit

    There is an option to get rid of the foul triangulation

     ComputationalGeometry`Methods`ConvexHull3D[{x, y, z} /. vertex,
                                    Graphics`Mesh`FlatFaces -> False]
    

    does the magic. Sample:

    alt text

    Edit 2

    As I mentioned in a comment, here are two sets of degenerate vertex generated by your randomCons

     {{x -> Sqrt[3/5]}, 
      {x -> -Sqrt[(5/3)] + Sqrt[2/3] y}, 
      {x -> -Sqrt[(5/3)], y -> 0}, 
      {y -> -Sqrt[(2/5)], x -> Sqrt[3/5]}, 
      {y -> 4 Sqrt[2/5],  x -> Sqrt[3/5]}
     }
    

    and

    {{x -> -Sqrt[(5/3)] + (2 z)/Sqrt[11]}, 
     {x -> Sqrt[3/5], z -> 0}, 
     {x -> -Sqrt[(5/3)], z -> 0}, 
     {x -> -(13/Sqrt[15]), z -> -4 Sqrt[11/15]}, 
     {x -> -(1/Sqrt[15]),  z -> 2 Sqrt[11/15]}, 
     {x -> 17/(3 Sqrt[15]), z -> -((4 Sqrt[11/15])/3)}
    }
    

    Still trying to see how to cope gently with those …

    Edit 3

    This code is not general enough for the full problem, but eliminates the cylinder degenerancy problem for your sample data generator. I used the fact that the pathogenic cases are always cylinders with their axis paralell to one of the coordinate axis, and then used RegionPlot3D to plot them.
    I’m not sure if this will be useful for your general case :(.

    For[i = 1, i <= 160, i++,
     rstatic = randomCons;
     r[i] = rstatic;
     s1 = Reduce[r[i], {x, y, z}] /. {x -> var1, y -> var2, z -> var3};
     s2 = Union[StringCases[ToString[FullForm[s1]], "var" ~~ DigitCharacter]];
    
     If [Dimensions@s2 == {3},
    
      (randeq = rstatic /. x_ >= y_ -> x == y;
       eqset = Subsets[randeq, {3}];
       vertexcandidates = Flatten[Table[Solve[eqset[[i]]], {i, Length[eqset]}], 1];
       vertex = Union[Select[vertexcandidates, rstatic /. # &]];
       a[i] = ComputationalGeometry`Methods`ConvexHull3D[{x, y, z} /. vertex, 
                Graphics`Mesh`FlatFaces -> False, Axes -> False, PlotLabel -> i])
      ,
    
       a[i] = RegionPlot3D[s1, {var1, -2, 2}, {var2, -2, 2}, {var3, -2, 2},
                 Axes -> False, PerformanceGoal -> "Quality", PlotPoints -> 50, 
                 PlotLabel -> i, PlotStyle -> Directive[Yellow, Opacity[0.5]], 
                 Mesh -> None]
      ];
     ]
    
    GraphicsGrid[Table[{a[i], a[i + 1], a[i + 2]}, {i, 1, 160, 4}]]
    

    Here you can find an image of the generated output, the degenerated cases (all cylinders) are in transparent yellow

    HTH!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate a linear regression on a scatter plot I have generated,
here in above screen, i have two linear layouts, one for two TextView and
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have you determined a maximum number of characters allowed in FCKEditor ? I seem
Have a n-tire web application and search often times out after 30 secs. How
Have you managed to get Aptana Studio debugging to work? I tried following this,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.