What shape is formed by the bounded coefficients of a quadratic polynomial with only real solutions when the coefficients act like 3D tuples?

71 Views Asked by At

Back Story

I believe a quadratic polynomial, $ax^2+bx+c$, has only real solutions $\text{iff}$ the discriminant, $D \geq 0$, which occurs when:

$$ D = b^2 - 4ac \geq 0 \Rightarrow \begin{cases} b^2 \geq 4ac & \text{if } ac > 0, \\ \text{any } b & \text{if } ac \leq 0. \end{cases} $$

I want to create a software program that generates random quadratic polynomials with only real solutions without using any 'if-statements' because if it requires checking, then by this logic I would have to reject a lot of generated quadratic polynomials when simulating.

In Mathematica, I can use the code:

n = 10000; (* Number of random sets to generate *)
data = Table[
  a = RandomReal[{-2, 2}];
  b = RandomReal[{-2.5, 2.5}];
  c = RandomReal[{-3, 3}];
  discriminant = b^2 - 4*a*c;
  If[discriminant  >= 0, {a, b, c}, Nothing],
  {n}
];
chm = ConcaveHullMesh[data];
bdp = MeshCoordinates[RegionBoundary[chm]];
ListSurfacePlot3D[bdp, AxesLabel -> {"a", "b", "c"}, PlotLabel -> "Coefficients of Quadratics with D >= 0"]

To generate a shape like this:

This is a sample image using the coefficients of a quadratic polynomial as 3D points.

When I change the bounds for $a, b, \text{or } c$, I get a similar shape where it is partially flat on the top and bottom, then curves. And it seems to have a flip symmetry.

Question Repeated:

So then what shape is formed that contains all the points (a, b, c) given the maximum and minimum bounds for each of those 3 parameters?

Update:

Here is the code and images for different viewpoints for when $b^{2} = 4ac$:

n = 10000; (* Number of random sets to generate *)
data = Table[
    a = RandomReal[{-2, 2}];
    c = RandomReal[{-3, 3}];
    If[RandomChoice[{True, False}], 
        b = 2 * Sqrt[Abs[a * c]], (* Ensure b is real *)
        b = -2 * Sqrt[Abs[a * c]]
    ];
    If[a < 0, c = -Abs[c]]; (* Ensure c is negative if a is negative *)
    If[c < 0, a = -Abs[a]]; (* Ensure a is negative if c is negative *)
    {a, b, c},
    {n}
];

viewPoints = {
    {"Above", {0, 0, Infinity}}, {"Below", {0, 0, -Infinity}},
    {"Front", {0, Infinity, 0}}, {"Behind", {0, -Infinity, 0}},
    {"Left", {Infinity, 0, 0}}, {"Right", {-Infinity, 0, 0}},
    {"Top Front Right", {Infinity, Infinity, Infinity}}, {"Bottom Back Left", {-Infinity, -Infinity, -Infinity}}
};

plots = Table[
    ListPlot3D[data, 
        ViewPoint -> vp[[2]], 
        ViewProjection -> "Orthographic", 
        ImagePadding -> 5,
        PlotLabel -> Style[vp[[1]], 14, Bold, Background -> White],
        PlotRangePadding -> 0.2
    ],
    {vp, viewPoints}
];

(* Adjust the size of the graphics grid as needed *)
Rasterize[GraphicsGrid[Partition[plots, 2], Spacings -> {0, 0}, ImageSize -> Full]]

Which gave the example image:

This is a sample plot from 8 different orthographic view points.

1

There are 1 best solutions below

0
On BEST ANSWER

So, looking at your graphs and reading the requirement, it is not possible to generate that surface without using an 'if'-statement somewhere in the code (possibly only shown at the lower level.) I don't have a proof of this statement, but I think it is self-evident.

While you cannot perfectly describe the shape, I believe you can randomly generate a decent subspace that gives you only real roots and it appears to not use any if statements (even though absolute values require it).

Here is the Mathematica Code:

GenerateQuadraticCoefficients[n_Integer] := Module[
  {a, b, c, k, coefficientLists},
  
  (* Function to generate a single set of coefficients *)
  generateSingleSet[] := Module[{a, b, c, k},
    a = RandomReal[{-2, 2}];
    c = -a * RandomReal[{-3, 3}] / Max[Abs[a], 1*^-6]; (* Avoid division by zero *)
    k = RandomReal[{1, 10}];
    b = 2 * Sqrt[Abs[a * c]] * k;
    {a, b, c}
  ];
  
  (* Generate the list of coefficient lists *)
  coefficientLists = Table[generateSingleSet[], {n}];
  
  coefficientLists
]

(* Example usage: generate 5 sets of coefficients *)
GenerateQuadraticCoefficients[5]

and you can then test it out with:

data = GenerateQuadraticCoefficients[10000];
Solve[Dot[First[RandomSample[data,1]],{x^2,x,1}]==0,x]

While it is not possible with a digital computer, I guess that maybe it is possible with a hybrid digital-analog computer. So, for example, making a 3D Etch-a-Sketch like the first photo in the question. The position of the nobs/rods would give the coordinates of the point in the strangely-shaped box. But making that would most likely be just silly.