> restart:
TP 05
Lecture de fichiers et
loi normale
Rappel de consignes
(1) titre en "Times New Roman", corps 36,
NOM Prénom - groupe
TP05 - date
(2) sauvegarder "souvent"
(3) imprimer : paginer (Format/Page_Number)
puis File/Preview.
enfin imprimer en deux colonnes
>
quelques bibliothèques
Vérifier les numéros de version des bibliothèmes disponibles
> with(pldx); # il faut la version 29
> with(simul); # il faut la version 19
Warning, the name ever_loaded has been redefined
Création du fichier
M, S:= 22, 5;
ra:= stats[random, normald[M,S]];
n:= 1000; li:= [ ra( n )]:
fich:= "F:/docs/Ensait/maotp/maotp08/dat_maotp08.txt";
hdl:= fopen(fich, WRITE);
for i to n do fprintf(hdl,"%a\n", li[i]); od:
fclose(fich):
M,S:= 'M', 'S':
>
Lecture du fichier
Télécharger le fichier "www.douillet.info/~douillet/maotp/maotp05/dat_maotp05.txt"
Déclarer le nom de la copie locale du fichier
> fich:= "F:/docs/Ensait/maotp/maotp05/dat_maotp05.txt";
On lit le premier nombre
>
hdl:= fopen(fich, READ);
fscanf(hdl,"%a");
fclose(fich);
On lit 5 nombres
>
lire:= table(): tmp:= 'tmp':
hdl:= fopen(fich, READ);
for i to 5 do
tmp:= fscanf(hdl,"%a");
lire[i]:= op (tmp);
od;
fclose(fich);
On lit tous les nombres
>
lire:= table(): tmp:= 'tmp':
hdl:= fopen(fich, READ);
for i while tmp <> [ ] do
tmp:= fscanf(hdl,"%a");
lire[i]:= op (tmp);
od:
fclose(fich); n:= i-2 ; i:='i':
On en fait une liste
> li:= [seq(lire[j], j=1..n)]:
>
Paramètres de dispersion
> xmacro();
> nbr(li);
> m:= moy(li);
> s, s2:= sqrt(var(li)), var(li);
>
aa, bb:= op(xab(li));
min(op(li)), max(op(li));
On écarte un peu les bornes
> aa, bb:= (aa-0.001*bb)/.999, (bb-0.001*aa)/.999;
>
Visualisation
>
xima:=proc(pl); op(1,pl) : convert(%,list): map(op,%):
map2(op,2,%): max(op(%)): end:
Histogramme automatique
> xhisto(li, area=1); pl1:= %:
>
yx:=xima(pl1):
plot([[m,y,y=0..yx], [m-s,y,y=0..yx], [m+s,y,y=0..yx]], color=red, linestyle=[24,8,8]); pl2:= %:
> display(pl1, pl2);
>
Histogramme avec choix des classes
> macro(talto = stats[transform, tallyinto] );
> kx:= 12; dx:= (bb-aa)/kx ;
> les_interv:= [ seq(aa+k*dx..aa+k*dx+dx, k=0..kx-1)];
> ta2:= talto(li, les_interv) ;
>
pl3:=xhisto(ta2):
yx:=xima(pl3) :
pl4:= plot([[m,y,y=0..yx], [m-s,y,y=0..yx], [m+s,y,y=0..yx]], color=red, linestyle=[24,8,8]):
> display( pl3, pl4);
> M= m, S=s; assign(%);
> pl5:= plot(norlaw(M,S, x), x=aa..bb, color=blue, linestyle=16):
> display(pl3,pl4,pl5);
>
Paramètres de dispersion (DG)
> ta2;
> m; moy(ta2)*1.;
> s2; var(ta2)*1.;
>
>
Histogramme loi normale
> les_interv;
> NL:= unapply(Norlaw(m,s,x), x);
> do_it:= proc(a,b) Weight(a..b, (NL(b)-NL(a))*n) end;
> ta_th:= map(do_it@op, les_interv);
> xhisto(ta_th, color=yellow); pl7:=%:
> display(pl3, pl7);
>
>
Expliquer pourquoi cela ne va pas.
Et corriger ...
> ta_min:= [seq(`if`(op(2,ta2[k])<op(2,ta_th[k]) , ta2[k], ta_th[k]), k=1..nops(ta2))];
> xhisto(ta_min, color=pink): display(%, pl3,pl7);
> [nbr,moy,var](ta_th); [n,m,s^2];
>
>
>
>