I am trying to plot a function in *Mathematica* that is defined over the unit simplex. To take a random example, suppose I want to plot sin(x1*x2*x3) over all x1, x2, x3 such that x1, x2, x3 >= 0 and x1 + x2 + x3 = 1. Is there a neat way of doing so, other than the obvious way of writing something like

```
Plot3D[If[x+y<=1,Sin[x y(1-x-y)]],{x,0,1},{y,0,1}]
```

?

What I want, ideally, is a way of plotting **only** over the simplex. I found the website http://octavia.zoology.washington.edu/Mathematica/ which has an old package, but it doesn't work on my up-to-date version of *Mathematica*.

Try:

```
Plot3D[Sin[x y (1 - x - y)], {x, 0, 1}, {y, 0, 1 - x}]
```

But you can also use `Piecewise`

and `RegionFunction`

:

```
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]]
```

If you want to get symmetric looking plots like in that package you linked, you need to figure out rotation matrix that puts the simplex into x/y plane. You can use this function below. It's kind of long because I left in the calculations to figure out simplex centering. Ironically, transformation for 4d simplex plot is much simpler. Modify `e`

variable to get different margin

```
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]
]
```

Here's how to use it

```
simplexPlot[Sin[#1 #2 #3] &, Plot3D]
```

```
simplexPlot[Sin[#1 #2 #3] &, DensityPlot]
```

If you want to see domain in the original coordinate system, you could rotate the plot back to the simplex

```
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]
```

Here's another simplex plot, using traditional 3d axes from here and `MeshFunctions->{#3&}`

, complete code here

Similar Questions

Uhh Sorry its really hard to explain but. This is already a string: login_username=Username&login_password=Password&login_submit=Submit How can i replace 'Username' with a pre-defined strin

I want to generate a plot like the following I am not sure how to generate a shading even though I can get the frame done. I'd like to know the general approach to shade certain areas in a plot in Ma

I'm using Code First to map classes to an existing database. I need a way to unit test these mappings, which are a mix of convention-based, attribute-based, and fluent-api. To unit test, I need to con

This question already has an answer here: 3D equivalent of the curve function in R? 2 answers If x and y can vary from 0 to 10, how can I plot a maths function z = x*(y^2) as an image plot or h

I reduced a debugging problem in Mathematica 8 to something similar to the following code: f = Function[x, list = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5}; Count[list, x] ]; f[4] Maximize{f[x], x, Integers]

I an using knitr for automatic html reports. I would like to be able to plot simple scatter plots (like time serie plots) but interactive ones, that would be zoomable. Ideally I could then use it in a

Just curious how Mathematica users debug their code when encounter run-time errors. I feel Mathematica is so powerful that most programming tasks can be replaced with it but when it has bugs the incon

How can I convert .eps to .pdf inside Mathematica (perhaps using GhostScript?)?

In Mathematica, how can I simplify expressions like a == b || a == -b into a^2 = b^2? Every function that I have tried (including Reduce, Simplify, and FullSimplify) does not do it. Note that I want t

I'm trying to use 2 color functions within one matrix plot in mathematica. Is this possible to do? For example, using a very simple matrix: test = Partition[Table[i, {i, 1, 9}], 3] I would like to ma

I've switch to using VS 2012 and for most parts it is great. The problem is I can't find how to filter my unit test by category?

Ive been having some trouble using Plot to graph a complicated composite function. I am trying to plot the ArgMax of a composite function F[]. F[] involves several levels of nested composite functio

I'm using Symfony2. How can I access parameters defined in parameters.yml from within a twig template ? Thanks.

a=2; b=9; %the variance syms x i0=besseli(0,a*x/b); fx=(x/b)*exp(-(x^2+a^2)/(2*b))*i0; fun=matlabFunction(x*fx); mean=quad(fun,0,282); How can I plot fx and the integral of fx?

I wrote the code for the secant algorithm , and now I have the function : f(x) = 2x^3 - 4x^2 + 3x , with two initial points : x0 = -1 , x1 = 2 . My question is how can I plot the function that I wro

I want to write a function to force Mathematica to show a rational number in a denominator I specified. For example, the rational 2/3 with the specified denominator 6 should become 4/6. I tried using

I'm very new to Mathematica. I want to use it as a data source for gnuplot (I know Mathematica can plot too), it uses a file format with data in columns and a space between each column on each row. Li

I can do this in MATLAB easily but I'm trying to do it Mathematica. I have a 27000 element (15 minutes*30 measurements per second) list of wind speed values. I want to find the max value in each 2700

I have the following problem: I am using hist() in matplotlib.pyplot I am trying to create 4 histograms on the same graph. and an approximation gaussian for each one of them. how can I plot the 4 hist

I have a question about NDSolve function in Mathematica. I have an oscillator defined by these two equations: x' = v v' = -x - u*v^3 where u is some constant. How to create an NDSolve that resolves t

I'm trying to use the scipy Nelder-Mead simplex search function to find a minimum to a non-linear function. It appears my simplex gets stuck because it starts off with an initial simplex that is too s

So I'm trying to knock out this last problem, and I'm following my teacher's guide but my graph seems to still be off, the problem is: Use the FindRoot command in Mathematica to define an inverse func

I am trying to draw a line which is a gradient. How is that possible in canvas?

How do I Start a job of a function i just defined? function FOO { write-host HEY } Start-Job -ScriptBlock { FOO } | Receive-Job Receive-Job: The term 'FOO' is not recognized as the name of cmdlet, f

I ran into this problem when I try to solve a partial differential equation. Here is my code: dd = NDSolve[{D[tes[t, x], t] ==D[tes[t, x], x, x] + Exp[-1/(tes[t, x])], tes[t, 0] == 1, tes[t, -1] == 1,

I am trying to unit test my custom angular js directive. The directive does a date validation based on a regex: var app = angular.module('myApp', []); app.directive('myValidation', function () { retur

I have a function that strips the youtube id off a url. I then want to use this function 10 time per page (in the wordpress loop). The function works great when I feed it the url within my function sc

I'm trying out MVVM Light, partly inspired by the EventToCommand capabilities which seem to make it easier to handle drag-and-drop from outside my app in the View Model and in the XAML. However I am a

Good evening, I am working to get my head around unit testing and I'm having a little trouble determining how far I can push unit testing before it turns into integration testing. An example from the

Mathematica: Filling an infinitely deep potential well Comment: The proper page for Mathematica questions is this one I would like to visualize a potential well for a particle in a box in Mathematica

Mathematica has ten basic plot markers which are used cyclically when making a ListPlot with PlotMarkers->Automatic. There are filled and empty versions of circle, square, diamond, up triangle, and

I am trying to replicate Lagrange Interpolating Polynomials in Mathematica. The wiki for an explanattion of them can be seen here. This is my code (sorry I don't know how to place mathematica code in

I started using R's map() function to plot maps. I noticed that when I resize the plot window, the image does not scale to fill the window. How can I get the map image to automatically resize bigger o

I am trying to plot the ranges of different cellular base stations in matlab, like this : http://i.imgur.com/smEno.jpg But I can't figure out how...

when setting up a plot for matplotlib, i run into very large numbers. in one plot, these get converted into the scientific format, which i like, in another one they don't get converted. How can i spe

Gnuplot uses only positive square root values when sqrt(x) is used. Is there a way to plot both positive and negative values in the same function. I know of a hack which is to use f(x) = sqrt(x) and g

Here is my partial view: <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl %> <script type=text/javascript> function myFunction() { .... } </script> ....other htm

I'm working with the Struts2 framework and would like to unit test the execute method below: public String execute() { setDao((MyDAO) ApplicationInitializer.getApplicationContext().getBean(MyDAO));

I have a question, how can I get the data values from a function in gnuplot?. For example I do plot [0:pi] sin(x) but I want to get the data values from this plot, how can I do that?. Thanks in adva

This was bugging me over the weekend: What is a good way to solve those Where's Waldo? ['Wally' outside of North America] puzzles, using Mathematica (image-processing and other functionality)? Here is

I'm not sure I got how to define private functions right. When I'm writing a package mathematica, I just do this: BeginPackage[myPackage`] myPublicFunction::usage=myPublicFunction blahblahblah; Be

Using plot in R causes the factors on the x-axis to be alphabetically ordered. How can I specify the order of the factors on the x-axis? Example: y <- 1:9 x <- c(rep(B, 3), rep(A, 3), rep(

Doing a little machine learning, and working on some linear regression. I can't seem to plot this in Matlab. Given a bunch of data how do I plot in matlab? I know it should be parabolic, but my co

For example, I want to plot the function f(x,y) =sin(x^2+y^2)/(x^2+y^2), x^2+y^2 <=4π In Mathematica, I can do it as following: Plot3D[Sin[x^2 + y^2]/(x^2 + y^2), {x, -4, 4}, {y, -4, 4}, RegionFun

Is it true that Mathematica's Minimize function does not allow constraints like Mod[x,2]==0? I am trying to solve a MinuteMath puzzle with Mathematica: What is the smallest possible average of four d

Imagine I've defined a recursive factorial in Mathematica, like this: Clear[fact] fact[0] = 1 fact[n_] := n fact[n - 1] Evaluating fact[10] confirms that the function works and terminates. A bit of a

I'd like to be able to unit test my Arduino code. Ideally, I would be able to run any tests without having to upload the code to the Arduino. What tools or libraries can help me with this? There is an

I have some data which is collected for 6 days during 8:00AM to 11:00AM. I need to plot all the data on same plot one over other. The way I am doing now, hold on plot(y1,x1,':b*','MarkerEdgeColor','k'

Like the title says, I'd like to put my javascript under unit test, how can I isolate my $.publish() and $.subscribe() calls? I'm using QUnit right now, but only have a few tests, so I'd be willing to

I have a function f(x,t) and I'd like to plot the function of the solution x(t) of f(x(t),t)=0 using Mathematica. How can I do it? Mathematica is often quite different to other programming languages I