Wolfram mathematica 如何在Mathematica中绘制单位单纯形上定义的函数?
我试图在Mathematica中绘制一个函数,它是在单位单纯形上定义的。举一个随机的例子,假设我想在所有x1,x2,x3上绘制sin(x1*x2*x3),这样x1,x2,x3>=0,x1+x2+x3=1。 有没有一种简洁的方式,除了写这样的东西Wolfram mathematica 如何在Mathematica中绘制单位单纯形上定义的函数?,wolfram-mathematica,plot,Wolfram Mathematica,Plot,我试图在Mathematica中绘制一个函数,它是在单位单纯形上定义的。举一个随机的例子,假设我想在所有x1,x2,x3上绘制sin(x1*x2*x3),这样x1,x2,x3>=0,x1+x2+x3=1。 有没有一种简洁的方式,除了写这样的东西 Plot3D[If[x+y<=1,Sin[x y(1-x-y)]],{x,0,1},{y,0,1}] Plot3D[如果[x+y尝试: 但您也可以使用分段和区域函数: Plot3D[Piecewise[{{Sin[x y (1 - x - y)
Plot3D[If[x+y<=1,Sin[x y(1-x-y)]],{x,0,1},{y,0,1}]
Plot3D[如果[x+y尝试:
但您也可以使用分段
和区域函数
:
Plot3D[Piecewise[{{Sin[x y (1 - x - y)],
x >= 0 && y >= 0 && x + y <= 1}}], {x, 0, 1}, {y, 0, 1},
RegionFunction -> Function[{x, y}, x + y <= 1]]
Plot3D[分段[{{Sin[xy(1-x-y)],
x>=0&&y>=0&&x+y函数[{x,y},x+y如果你想得到像你链接的软件包中那样的对称图,你需要计算出将单纯形放入x/y平面的旋转矩阵。你可以使用下面的函数。它有点长,因为我在计算中留下来计算单纯形居中。具有讽刺意味的是,4d单纯形图的变换要简单得多。Modifye
变量以获得不同的边距
simplexPlot[func_, plotFunc_] :=
Module[{A, B, p2r, r2p, p1, p2, p3, e, x1, x2, w, h, marg, y1, y2,
valid},
A = Sqrt[2/3] {Cos[#], Sin[#], Sqrt[1/2]} & /@
Table[Pi/2 + 2 Pi/3 + 2 k Pi/3, {k, 0, 2}] // Transpose;
B = Inverse[A];
(* map 3d probability vector into 2d vector *)
p2r[{x_, y_, z_}] := Most[A.{x, y, z}];
(* map 2d vector in 3d probability vector *)
r2p[{u_, v_}] := B.{u, v, Sqrt[1/3]};
(* Bounds to center the simplex *)
{p1, p2, p3} = Transpose[A];
(* extra padding to use *)
e = 1/20;
x1 = First[p1] - e/2;
x2 = First[p2] + e/2;
w = x2 - x1;
h = p3[[2]] - p2[[2]];
marg = (w - h + e)/2;
y1 = p2[[2]] - marg;
y2 = p3[[2]] + marg;
valid =
Function[{x, y}, Min[r2p[{x, y}]] >= 0 && Max[r2p[{x, y}]] <= 1];
plotFunc[func @@ r2p[{x, y}], {x, x1, x2}, {y, y1, y2},
RegionFunction -> valid]
]
(来源:)
(来源:)
如果要在原始坐标系中查看域,可以将绘图旋转回单纯形
t = AffineTransform[{{{-(1/Sqrt[2]), -(1/Sqrt[6]), 1/Sqrt[3]}, {1/
Sqrt[2], -(1/Sqrt[6]), 1/Sqrt[3]}, {0, Sqrt[2/3], 1/Sqrt[
3]}}, {1/3, 1/3, 1/3}}];
graphics = simplexPlot[5 Sin[#1 #2 #3] &, Plot3D];
shape = Cases[graphics, _GraphicsComplex];
Graphics3D[{Opacity[.5], GeometricTransformation[shape, t]},
Axes -> True]
(来源:)
这里是另一个单纯形图,使用和MeshFunctions->{3&}
中的传统3d轴,完成代码
(来源:)谢谢,@Yaroslav。不过,我真正希望的是轴沿着单纯形的侧面,这样我们就可以真正认为绘图就在单纯形上。我想,一个可以接受的替代方法是删除边框,并在角点x1=1、x2=1和x3=1上加上标签(当第三个变量等于1时,其余两个变量隐式为零)。再次感谢@Yaroslav。我想象的是一个与上面第一个图形类似的情节,但没有封闭框,并且角落都贴有适当的标签。但现在你给了我所有这些提示,我可能应该自己解决,而不是搭便车在你身上!封闭框由Frame
选项控制,你可以使用co带标签的rner标签=图形[文本[#,p2r@#]&/@IdentityMatrix@3]使用Show
组合原始绘图和标签。这些结果与我在原始问题中发布的代码相同。
simplexPlot[Sin[#1 #2 #3] &, Plot3D]
simplexPlot[Sin[#1 #2 #3] &, DensityPlot]
t = AffineTransform[{{{-(1/Sqrt[2]), -(1/Sqrt[6]), 1/Sqrt[3]}, {1/
Sqrt[2], -(1/Sqrt[6]), 1/Sqrt[3]}, {0, Sqrt[2/3], 1/Sqrt[
3]}}, {1/3, 1/3, 1/3}}];
graphics = simplexPlot[5 Sin[#1 #2 #3] &, Plot3D];
shape = Cases[graphics, _GraphicsComplex];
Graphics3D[{Opacity[.5], GeometricTransformation[shape, t]},
Axes -> True]