I am trying to draw the 'level curves' of the following function:

enter image description here

where the variables are restricted such that x,y are non-negative, and x+y is less than or equal to one. In other words, this is a function of a vector (x(1),x(2),x(3)) such that the elements all add up to 1. So for example, I would want to set z=0.5 and plot the function for different values of z. If anyone has a simple example of this kind of paramaterisation it would be really helpful.



  axis lines=center,
\addplot3[patch,blue!70!black!50,forget plot] 
\addplot3[no markers,red!90!black] 
   \addplot3[domain=0:0.5,y domain=0:0.5, red, thick,samples=50] {x*ln(3*x)+y*ln(3*y)+(1-x-y)*ln(3*(1-x-y)) };

\node[fill=red!90!black,inner sep=1pt,circle,label={180:$Y$}] 
  at (axis cs:0.1,0.26,0.64) {};  


my goal is to get something along the lines of: enter image description here

  • @CroCo updated to include my attempt – WeakLearner Sep 18 '15 at 12:14
  • Contouring is not easy and doing it with pgfmath is just plain wasteful. – John Kormylo Sep 20 '15 at 15:46
  • Is a lualatex solution acceptable? – JPi Sep 24 '15 at 2:19
  • @JPi yes, that would be great – WeakLearner Sep 24 '15 at 3:14
  • ok, will try to do on the weekend; hope the deadline can be extended – JPi Sep 24 '15 at 18:57

I am not sure if I have understood the mathematical problem correctly, because you are talking about two different $z$ values. I assume that the $z$ on the left hand side of the equation is the same as on the right, written as $(1-x-y)$ and replaced the one on the left with the one on the right. Then the problem is reduced to two variables. Next I have moved the left $z$ to the right hand side of the equation, so it now shows as $0 = x ln[3x] + y ln[3y] + (1-x-y) ln[3(1-x-y)] - (1-x-y)$.

Unfortunately the variables cannot be separated, so by giving for example $x$ values you have to solve for the corresponding $y$ values in an external program. This is a quite easy task, because it is a simple root search.

Having then the $x$ and $y$ values the corresponding $z$ values can be calculated again and you can plot the result. Here I used the ternary library of pgfplots which you can find in section 5.13 of the PGFPlots manual on page 487 (v1.13).

            ternary limits relative=false,
            no markers,
            \addplot3+ [thick] table {
                x           y           z
                1.000E-10   5.813E-01   4.187E-01
                2.500E-02   6.280E-01   3.470E-01
                5.000E-02   6.457E-01   3.043E-01
                1.000E-01   6.542E-01   2.458E-01
                1.500E-01   6.444E-01   2.056E-01
                2.000E-01   6.237E-01   1.763E-01
                2.500E-01   5.954E-01   1.546E-01
                3.000E-01   5.611E-01   1.389E-01
                3.500E-01   5.217E-01   1.283E-01
                4.000E-01   4.777E-01   1.223E-01
                4.500E-01   4.291E-01   1.209E-01
                5.000E-01   3.753E-01   1.247E-01
                5.500E-01   3.147E-01   1.353E-01
                6.000E-01   2.425E-01   1.575E-01
                6.250E-01   1.974E-01   1.776E-01
                6.500E-01   1.294E-01   2.206E-01
                6.525E-01   7.179E-02   2.757E-01
                6.350E-01   3.269E-02   3.323E-01
                6.120E-01   1.251E-02   3.755E-01
                5.813E-01   1.000E-10   4.187E-01

image showing the result of above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.