> restart:

TP 06

Lecture de fichiers et

loi lognormale

Rappel de consignes

(1) titre en "Times New Roman", corps 36,

NOM Prénom - groupe

TP06 - date

(2) sauvegarder "souvent"

(3) imprimer : paginer (Format/Page_Number)

puis File/Preview.

enfin imprimer en deux colonnes

>

On charge quelques bibliothèques

Vérifier les numéros de version des bibliothèmes disponibles

> with(pldx); # il faut la version 27
ever_loaded;

`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, ...

[` Diag`, ` Entries`, ` Evalm`, ` Matrice`, ` Tr`, ...
[` Diag`, ` Entries`, ` Evalm`, ` Matrice`, ` Tr`, ...

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

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

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

[` Chi2`, ` Gauss`, ` IChi`, ` IGauss`, ` INorlaw`,...
[` Chi2`, ` Gauss`, ` IChi`, ` IGauss`, ` INorlaw`,...

> xmacro();

moy, var, cov, xab, nbr

Création du fichier

>

Lecture du fichier

Télécharger le fichier "www.douillet.info/~douillet/maotp/maotp07/dat_maotp07.txt"

Déclarer le nom de la copie locale du fichier

> fich:= "F:/docs/Ensait/maotp/maotp06/dat_maotp06.txt";

fich :=

On lit le premier nombre

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

hdl := 0

[1977.948446]

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

> m:= moy(li);

m := 1155.268532

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

s, s2 := 731.0392416, 534418.3728

> vals:= xab(li);
nbr(li);

vals := 165.4319730 .. 6265.849514

1000

>

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

yx := .7356873473e-3

[Maple Plot]

> display(pl1, pl2);

[Maple Plot]

>

Histogramme avec choix des classes

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

moy, var, cov, xab, nbr, talto

> dx:= 150; kx:=30; seq(k*dx..k*dx+dx, k=0..kx), dx*(kx+1).. ceil(rhs(vals)):
les_interv:= [%];

dx := 150

kx := 30

les_interv := [0 .. 150, 150 .. 300, 300 .. 450, 45...
les_interv := [0 .. 150, 150 .. 300, 300 .. 450, 45...
les_interv := [0 .. 150, 150 .. 300, 300 .. 450, 45...
les_interv := [0 .. 150, 150 .. 300, 300 .. 450, 45...

> ta2:= talto(li, les_interv) ;

ta2 := [Weight(0 .. 150,0), Weight(150 .. 300,20), ...
ta2 := [Weight(0 .. 150,0), Weight(150 .. 300,20), ...
ta2 := [Weight(0 .. 150,0), Weight(150 .. 300,20), ...
ta2 := [Weight(0 .. 150,0), Weight(150 .. 300,20), ...
ta2 := [Weight(0 .. 150,0), Weight(150 .. 300,20), ...
ta2 := [Weight(0 .. 150,0), Weight(150 .. 300,20), ...
ta2 := [Weight(0 .. 150,0), Weight(150 .. 300,20), ...

> 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': K:='K': m=M*sqrt(K), (s/m)^2 = K-1; solve({%});
assign(%);

1155.268532 = M*sqrt(K), .4004197522 = K-1

{K = 1.400419752, M = 976.2337775}

> M, K;

976.2337775, 1.400419752

> pl5:= plot(norlaw(ln(M), sqrt(ln(K)), ln(x))/x, x=vals, color=blue, linestyle=16):

> display(pl3,pl4,pl5);

[Maple Plot]

>

Loi "en masse"

> ta2;

[Weight(0 .. 150,0), Weight(150 .. 300,20), Weight(...
[Weight(0 .. 150,0), Weight(150 .. 300,20), Weight(...
[Weight(0 .. 150,0), Weight(150 .. 300,20), Weight(...
[Weight(0 .. 150,0), Weight(150 .. 300,20), Weight(...
[Weight(0 .. 150,0), Weight(150 .. 300,20), Weight(...
[Weight(0 .. 150,0), Weight(150 .. 300,20), Weight(...
[Weight(0 .. 150,0), Weight(150 .. 300,20), Weight(...

> recode:= proc(item) global m; local a,b, c;
a,b,c:= op(op(1,item)), op(2, item);
Weight(a..b, c*(a+b)/2/m)
end;

recode := proc (item) local a, b, c; global m; a, b...
recode := proc (item) local a, b, c; global m; a, b...

> ta3:= map(recode, ta2);

ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...
ta3 := [Weight(0 .. 150,0.), Weight(150 .. 300,3.89...

> nbr(ta3);

1000.862542

> m_:= moy(ta3)*1.; v_:= var(ta3)*1.; s_:= sqrt(%);

m_ := 1627.542732

v_ := 1030232.949

s_ := 1015.003916

> pl23:=xhisto(ta3, area=1):
yx:=xima(pl23) :
pl24:= plot([[m_,y,y=0..yx], [m_-s_,y,y=0..yx], [m_+s_,y,y=0..yx]], color=red, linestyle=[24,8,8]):

> pl25:= plot(norlaw(ln(M*K), sqrt(ln(K)), ln(x))/x, x=vals, color=blue, linestyle=16):

> display( pl23, pl24,pl25);

[Maple Plot]

> m_; (s/m)^2+1; m*%;

1627.542732

1.400419752

1617.860871

>

>

>