> 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

`pldx v68-27  ;  author : <douillet@ensait.fr>  ;  ...

[Xtens, `convert/D2`, ever_loaded, isdiag, sinsin, ...
[Xtens, `convert/D2`, ever_loaded, isdiag, sinsin, ...
[Xtens, `convert/D2`, ever_loaded, isdiag, sinsin, ...

> with(simul); # il faut la version 19

`simul v68-19  ;  author : <douillet@ensait.fr>  ; ...

Warning, the name ever_loaded has been redefined

[chi2_tst, ever_loaded, histo, histo_arr, xcutn, xh...

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";

fich :=

On lit le premier nombre

> hdl:= fopen(fich, READ);
fscanf(hdl,"%a");
fclose(fich);

hdl := 0

[15.44965838]

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);

hdl := 0

tmp := [15.44965838]

lire[1] := 15.44965838

tmp := [27.67245061]

lire[2] := 27.67245061

tmp := [24.54458903]

lire[3] := 24.54458903

tmp := [16.49771368]

lire[4] := 16.49771368

tmp := [17.12753403]

lire[5] := 17.12753403

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':

hdl := 0

n := 1000

On en fait une liste

> li:= [seq(lire[j], j=1..n)]:

>

Paramètres de dispersion

> xmacro();

moy, var, cov, xab, nbr

> nbr(li);

1000

> m:= moy(li);

m := 21.95573327

> s, s2:= sqrt(var(li)), var(li);

s, s2 := 5.076065102, 25.76643692

> 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;

aa, bb := 3.20472004, 38.67230630

3.20472004, 38.67230630

aa, bb := 3.169216951, 38.70780939

>

Visualisation

> xima:=proc(pl); op(1,pl) : convert(%,list): map(op,%):
map2(op,2,%): max(op(%)): end:

Histogramme automatique

> xhisto(li, area=1); pl1:= %:

[Maple Plot]

> 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:= %:

[Maple Plot]

> display(pl1, pl2);

[Maple Plot]

>

Histogramme avec choix des classes

> macro(talto = stats[transform, tallyinto] );

moy, var, cov, xab, nbr, talto

> kx:= 12; dx:= (bb-aa)/kx ;

> les_interv:= [ seq(aa+k*dx..aa+k*dx+dx, k=0..kx-1)];

kx := 12

dx := 2.961549370

les_interv := [3.169216951 .. 6.130766321, 6.130766...
les_interv := [3.169216951 .. 6.130766321, 6.130766...
les_interv := [3.169216951 .. 6.130766321, 6.130766...
les_interv := [3.169216951 .. 6.130766321, 6.130766...

> ta2:= talto(li, les_interv) ;

ta2 := [Weight(3.169216951 .. 6.130766321,2), Weigh...
ta2 := [Weight(3.169216951 .. 6.130766321,2), Weigh...
ta2 := [Weight(3.169216951 .. 6.130766321,2), Weigh...
ta2 := [Weight(3.169216951 .. 6.130766321,2), Weigh...
ta2 := [Weight(3.169216951 .. 6.130766321,2), Weigh...

> 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);

[Maple Plot]

> M= m, S=s; assign(%);

M = 21.95573327, S = 5.076065102

> pl5:= plot(norlaw(M,S, x), x=aa..bb, color=blue, linestyle=16):

> display(pl3,pl4,pl5);

[Maple Plot]

>

Paramètres de dispersion (DG)

> ta2;

[Weight(3.169216951 .. 6.130766321,2), Weight(6.130...
[Weight(3.169216951 .. 6.130766321,2), Weight(6.130...
[Weight(3.169216951 .. 6.130766321,2), Weight(6.130...
[Weight(3.169216951 .. 6.130766321,2), Weight(6.130...
[Weight(3.169216951 .. 6.130766321,2), Weight(6.130...

> m; moy(ta2)*1.;

21.95573327

21.95728616

> s2; var(ta2)*1.;

25.76643692

26.23921084

>

>

Histogramme loi normale

> les_interv;

[3.169216951 .. 6.130766321, 6.130766321 .. 9.09231...
[3.169216951 .. 6.130766321, 6.130766321 .. 9.09231...
[3.169216951 .. 6.130766321, 6.130766321 .. 9.09231...

> NL:= unapply(Norlaw(m,s,x), x);

NL := proc (x) options operator, arrow; .5000000000...

> do_it:= proc(a,b) Weight(a..b, (NL(b)-NL(a))*n) end;

do_it := proc (a, b) Weight(a .. b,(NL(b)-NL(a))*n)...

> ta_th:= map(do_it@op, les_interv);

ta_th := [Weight(3.169216951 .. 6.130766321,.804380...
ta_th := [Weight(3.169216951 .. 6.130766321,.804380...
ta_th := [Weight(3.169216951 .. 6.130766321,.804380...
ta_th := [Weight(3.169216951 .. 6.130766321,.804380...
ta_th := [Weight(3.169216951 .. 6.130766321,.804380...
ta_th := [Weight(3.169216951 .. 6.130766321,.804380...

> xhisto(ta_th, color=yellow); pl7:=%:

[Maple Plot]

> display(pl3, pl7);

[Maple Plot]

>

>

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))];

ta_min := [Weight(3.169216951 .. 6.130766321,.80438...
ta_min := [Weight(3.169216951 .. 6.130766321,.80438...
ta_min := [Weight(3.169216951 .. 6.130766321,.80438...
ta_min := [Weight(3.169216951 .. 6.130766321,.80438...
ta_min := [Weight(3.169216951 .. 6.130766321,.80438...
ta_min := [Weight(3.169216951 .. 6.130766321,.80438...

> xhisto(ta_min, color=pink): display(%, pl3,pl7);

[Maple Plot]

> [nbr,moy,var](ta_th); [n,m,s^2];

[999.4095602, 21.94896194, 26.30028138]

[1000, 21.95573327, 25.76643692]

>

>

>

>