// gm.asy - dernière modification : 02/02/10 // Extension personnelle (mon fourre-tout) définissant // des constantes, commandes et environnements pour Asymptote. // G. Marris import stats; import geometry; import graph; import animate; /////////////////////////////////////////////////////////// ////////// STATISTIQUES /////////////////////////////////////////////////////////// // histogramm défini dans stats.asy : // void histogram(picture pic=currentpicture, real[] bins, real[] count, // real low=-infinity, // pen fillpen=nullpen, pen drawpen=nullpen, bool bars=false, // Label legend="", real markersize=legendmarkersize) void histogramme(picture pic=currentpicture, real[] tabxi, real[] tabni, bool bars=true, pen p1=lightgray, pen p2=.8bp+blue, string libellecaractere="Valeurs du caract\`ere", real minaxe=min(tabxi), real maxaxe=max(tabxi), real uniteaxe=(maxaxe-minaxe)/4, string libelleunite="", bool frequence=false, bool pourcent=false, real uniteaire=sum(tabni)/100){ real uniteairetempo; if(frequence==false) uniteairetempo=uniteaire; if(frequence==true && pourcent==false) { if(uniteaire>=1) uniteaire=uniteaire/100; uniteairetempo=uniteaire*sum(tabni); } if(frequence==true && pourcent==true) { uniteairetempo=uniteaire*sum(tabni)/100; } // Une variable utile pour déterminer la plus petite amplitude : real largeurunite=abs(tabxi[1]-tabxi[0]); // ... et une autre pour le numéro de classe correspondant : int iclasse=0; // Calcul des hauteurs (et de la plus petite amplitude de classe) : real[] tabhi; for(int i=0; i < tabni.length; ++i){ tabhi[i]=tabni[i]/(tabxi[i+1]-tabxi[i]); if (largeurunite>abs(tabxi[i+1]-tabxi[i])) { largeurunite=abs(tabxi[i+1]-tabxi[i]); iclasse=i; } } // Hauteur du rectangle le plus haut pour placer l'unité au dessus. real hauteurmaxi=max(tabhi); // Calcul de la hauteur à donner au rectangle unité d'aire real hauteurunite=(uniteairetempo/tabni[iclasse])*tabhi[iclasse]; // Tracé de l'histogramme histogram(tabxi,tabhi,low=0,bars=bars,p1,p2); // Tracé de l'unité d'aire et son étiquette filldraw(shift(truepoint(N+W))*box((0,0),(largeurunite,hauteurunite)),p1,p2); label(libelleunite+(string) uniteaire+(pourcent==true ? "\%": ""),truepoint(N+W)+(largeurunite,-hauteurunite/2),E); // Ajout de l'axe gradué xaxis(libellecaractere, Bottom, minaxe,maxaxe, RightTicks(Label(currentpen+fontsize(6)), Step=uniteaxe),above=true); } //////////////////////////////////////////////////////////////// ////////// ANIMATION D'UNE FAMILLE DE FONCTIONS (paramètre réel) //////////////////////////////////////////////////////////////// animation animpdf_famille_fonctions(real f(real,real), real xmin, real xmax, real ymin, real ymax, real[] valk, int n=400, pen[] stylo={black}){ animation Anim; int compteur=0; for (real k : valk) { real fk(real x){return f(x,k);} save(); path Cf=graph(fk,xmin,xmax,n=n); draw(Cf,1bp+stylo[compteur%stylo.length]); xlimits(xmin,xmax,Crop); ylimits(ymin,ymax,Crop); xaxis(Label("$x$",position=EndPoint, align=NE), xmin=xmin,xmax=xmax, Ticks(scale(.7)*Label(align=E), NoZero, begin=false,beginlabel=false, end=false,endlabel=false, Step=1,step=.25, Size=1mm, size=.5mm, pTick=black,ptick=gray), Arrow); yaxis(Label("$y$",position=EndPoint, align=NE), ymin=ymin,ymax=ymax, Ticks(scale(.7)*Label(), NoZero, begin=false,beginlabel=false, end=false,endlabel=false, Step=1,step=.25, Size=1mm, size=.5mm, pTick=black,ptick=gray), Arrow); label(format("$k=%f$",k),truepoint(N),N); Anim.add(); restore(); ++compteur; } return Anim; } ////////////////////////////////////////////////////////////////// /// OBTENIR UN TABLEAU DE VARIATION BASIQUE, SANS VALEUR INTERDITE ////////////////////////////////////////////////////////////////// picture tabvar(Label var="$x$", Label fonct="$f$", string[] lx, string[] ly, real[] v, real x1=1, real x2=2, real y1=1, real y2=3, pen styletrait=1bp+black) { picture pic; int n=lx.length-1; draw(pic,box((0,0),(2*x1+n*x2,-2*y1-y2)),styletrait); draw(pic,(0,-y1)--(2*x1+n*x2,-y1)^^(x1,0)--(x1,-2*y1-y2),styletrait); label(pic,var,(x1/2,-y1/2)); label(pic,fonct,(x1/2,-3/2*y1-y2/2)); real ymin=min(v), ymax=max(v); real[] vn; object[] im; real fx(real x) {return 3/2*x1+x*x2;} for(real y:v) vn.push(-3/2*y1-y2+(y-ymin)/(ymax-ymin)*y2); for(int i=0; i