探究仅含实根的二次多项式系数构成的3D有界区域形状
探究仅含实根的二次多项式系数构成的3D有界区域形状
我一直以来都记得,二次多项式 $ax^2+bx+c$ 只有实根的充要条件是判别式 $D \geq 0$,具体可以拆成两种情况:
$$
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}
$$
最近我琢磨着写个程序,能直接生成满足“仅含实根”条件的随机二次多项式系数,但不想用if语句做筛选——毕竟如果靠先随机生成再筛选的话,模拟时会扔掉大量不符合的样本,效率实在太低了。
最开始我用Mathematica写了一段筛选式的代码来观察这个区域的形状:
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"]
跑出来的3D形状有点意思:不管我调整a、b、c的取值范围,生成的区域都是上下部分平坦,中间带有曲线的形态,而且看起来明显有翻转对称性。
这就让我好奇了:给定a、b、c各自的最大最小值范围后,所有满足“二次多项式仅含实根”的点(a,b,c)构成的到底是什么形状?
更新:边界形态的多视角可视化
为了更清晰地观察这个区域的边界(也就是满足$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]]
这段代码生成了多视角的可视化图,能更直观地看到边界的具体形态。
备注:内容来源于stack exchange,提问作者Romogi
相关产品推荐
相关产品推荐

