# Spectrahedron mesh lines

The following is a spectrahedron region plot using 3 eigenvalues for mesh functions. It takes 22 seconds and mesh line quality is quite poor, any tips on making it nicer?

Already using PlotPoints->50, so is there another setting for controlling number of evaluation points for mesh lines?

roots = Eigenvalues[{{1, p1, p2}, {p1, 1, p3}, {p2, p3, 1}}];
eig1 = Function[{p1, p2, p3}, Evaluate@roots[[1]]];
eig2 = Function[{p1, p2, p3}, Evaluate@roots[[2]]];
eig3 = Function[{p1, p2, p3}, Evaluate@roots[[3]]];
RegionPlot3D[
Max@Eigenvalues@{{1, p1, p2}, {p1, 1, p3}, {p2, p3, 1}} < 2, {p1, -1,
1}, {p2, -1, 1}, {p3, -1, 1}, PlotPoints -> 50,
MeshFunctions -> {eig1, eig2, eig3}]


PS, doing region plots for the three eigenvalues is informative, but doesn't seem to translate well into Mesh lines

ContourPlot3D[eig1[p1, p2, p3], {p1, -1, 1}, {p2, -1, 1}, {p3, -1, 1}, RegionFunction -> Function[{x, y, z}, x < 0 || y > 0]]
ContourPlot3D[eig2[p1, p2, p3], {p1, -1, 1}, {p2, -1, 1}, {p3, -1, 1}, RegionFunction -> Function[{x, y, z}, x < 0 || y > 0]]
ContourPlot3D[eig3[p1, p2, p3], {p1, -1, 1}, {p2, -1, 1}, {p3, -1, 1}, RegionFunction -> Function[{x, y, z}, x < 0 || y > 0]]



Since the numeric roots/eigenvalues are real, they come in increasing order. Maybe this, then?:

Quiet[
RegionPlot3D[
eig3[p1, p2, p3] < 2, {p1, -1, 1}, {p2, -1, 1}, {p3, -1, 1},
PlotPoints -> 35, MeshFunctions -> {eig1, eig2}],
Less::nord]


• The problem with eig3 as a mesh function is that the surface coincides with a level set, up to a certain error. So the total range of eig3 over the OP's surface, which should be {2} is in fact {1.9991, 2.00002}, and the surface approximation error is determining the mesh lines. ("The surface approximation error" comes from truncating the refinement of the polygonal mesh approximating the boundary eig3[p1, p2, p3] == 2.) Commented Sep 29, 2021 at 3:41
• thanks, makes sense! Interesting that eig1 and eig2 mesh lines look identical even though region plots for those two functions look quite different Commented Sep 29, 2021 at 4:40
• @YaroslavBulatov Yes, I noticed that, but it wasn't immediately obvious why last night. However, from the characteristic polynomial, one has $e_1+e_2+e_3 = 3=$ trace of the matrix. So if two of the eigenvalues are constant along a trajectory, so is the third. You can save some time just specifying, say, eig2 as a mesh function. Commented Sep 29, 2021 at 12:55

Higher quality requires higher values for PlotPoints and MaxRecursion, and specifying a WorkingPrecision. These will all increase the timing.

Clear["Global*"]

\$Version

(* "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" *)

roots = Eigenvalues[{{1, p1, p2}, {p1, 1, p3}, {p2, p3, 1}}];

{eig1, eig2, eig3} = Function[{p1, p2, p3}, Evaluate@#] & /@ roots;

Column[
AbsoluteTiming[
RegionPlot3D[
Max@Eigenvalues@
{{1, p1, p2}, {p1, 1, p3}, {p2, p3, 1}} < 2,
{p1, -1, 1}, {p2, -1, 1}, {p3, -1, 1},
PlotPoints -> 135,
MaxRecursion -> 5,
MeshFunctions -> {eig1, eig2, eig3},
WorkingPrecision -> 30,
ImageSize -> 400,
PerformanceGoal -> "Quality"]]]
`