[metapost] drawing a beta-distribution?

Ph. Ivaldi jetable-pi-0 at tele2.fr
Fri Jan 11 11:30:44 CET 2008


Le 11 janvier 2008, Martin Kaffanke écrivit :

> Am Donnerstag, den 10.01.2008, 17:32 -0600 schrieb Troy Henderson:
>> I am running Octave 3.0.0, and it doesn't like referencing argv
>> directly.  Therefore, I have attached a "repaired" prob.m which fixes
>> the problem on my end.
>
> Hi there, I have troubles, I've never used octave before, so I
> installed  2.9 on my ubuntu.

I think Asymptote, the younger brother of Metapost, can do this job more
simply:
8<------8<------8<------8<------8<------8<------8<------8<------8<------
import graph;
unitsize(10cm,3cm);

typedef real realfcn(real);

realfcn betaDistribution(real alpha, real beta){
  return new real(real x){
    return gamma(alpha+beta)/(gamma(alpha)+gamma(beta))*
           x^(alpha-1)*(1-x)^(beta-1);
  };
};

real[][] ab=new real[][] {{0.5,0.5}, {5,1}, {1,3}, {2,2}, {2,5}};
pen[] p=new pen[] {0.8*red, 0.8*green, 0.8*blue, 0.8*magenta, black};

for (int i=0; i < 5; ++i) {
  draw(graph(betaDistribution(ab[i][0],ab[i][1]),1e-5,1-1e-5), bp+p[i],
       legend="$\alpha="+(string)ab[i][0]+
              ",\;\beta="+(string)ab[i][1]+"$");
}

xlimits(0,1,Crop);
ylimits(0,2.6,Crop);

xaxis("$x$",BottomTop,linewidth(bp),Ticks);
yaxis("$y$",LeftRight,linewidth(bp),Ticks(Step=0.2));

attach(scale(0.75)*legend(linelength=3mm),point(N),5S);
shipout(format="pdf");
8<------8<------8<------8<------8<------8<------8<------8<------8<------
Result here: http://cjoint.com/?bllrlSAqM2

-- 
   Philippe Ivaldi.
http://piprim.tuxfamily.org/


More information about the metapost mailing list