0

Edit: I want to generate points (x,y) such that x+y<=1.

[x,y] = meshgrid(0:.05:1, 0:.05:1);

Is it possible to use the output of the above result to to generate (x,y) such that x+y<=1.

You can ignore whatever is below. I got confused about what I am asking :) Previous: I want to plot the density function of Dirichlet distribution for points on the probability simplex in 3 dimensional space, that is, for p = (p1, p2, p3), p1+p2+p3 = 1. The distribution is given by

f(p1, p2, p3) = c*p1^(a1)*p2^(a2)*p3^(a3)

where c is a fixed normalization constant. Any help is appreciated.

Note: p1+p2+p3=1 such that p1>0, p2>0 p3>0 is a plane in 3 dimensions and hence 2 dimensional. Hence, it is possible to plot a function on this space.

user2808118
  • 129
  • 6
  • So you want to plot probability density as a function of 3 dimensions? How do you intend to even draw the fourth axis? – Luis Mendo Feb 12 '15 at 16:53
  • Sorry for the confusion. What I meant was something like this.. http://stackoverflow.com/questions/25504662/plotting-a-curve-on-probability-simplex – user2808118 Feb 12 '15 at 16:56
  • I realize my mistake. I will edit the question and post again. – user2808118 Feb 12 '15 at 16:58
  • Your best bet is to use [scatter3](http://mathworks.com/help/matlab/ref/scatter3.html?refresh=true) or [surf](http://mathworks.com/help/matlab/ref/surf.html) – knedlsepp Feb 12 '15 at 17:04
  • Have a look at these: http://stackoverflow.com/questions/10747860/4d-plot-display-variables-with-data-cursor-matlab and http://stackoverflow.com/questions/12224504/matlab-graph-plotting – knedlsepp Feb 12 '15 at 17:07
  • And what do you want to use as your two independent variables? You could for example use p1 and p2. (and substitute p3=1-p1-p2). Is that suitable for you? – Luis Mendo Feb 12 '15 at 17:10
  • I did the same. I guess that this works fine. Thanks. – user2808118 Feb 12 '15 at 17:11

2 Answers2

0

Let y = f(p1, p2, p3). Since p3 = 1 - p1 - p2, we only need to plot y = f(p1, p2), which is a 2-D function. This "2.5D" graph can be plot with MATLAB function mesh() or surf().

In case that there are constrains like p1 + p2 < 1, just make y = 0 or NaN for p1 + p2 >= 1. Just try and find which make the graph more pretty.

Meng Wang
  • 277
  • 1
  • 8
  • p1+p2+p3=1 such that p1>0, p2>0 p3>0 is a plane in 3 dimensions and hence 2 dimensional. Hence, it is possible to plot a function on this space. I was wondering if there is a well known approach to do the same in matlab. – user2808118 Feb 12 '15 at 17:01
0

I want to generate points (x,y) such that x+y<=1.

Your line

[x,y] = meshgrid(0:.05:1, 0:.05:1);

is a good start. It only remains to select the points of that grid that satisfy your condition. For that you use logical indexing:

ind = x+y<=1;
x = x(ind);
y = y(ind);

You can plot those points as a check:

plot(x,y,'.')
axis square

enter image description here

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147