Outils pour utilisateurs

Outils du site


info:2:fichiers_sources

Chapitre 2

Fichier Source

pays=["Algérie" "Égypte" "Libye" "Maroc" "Sahara occidental" "Soudan" "Tunisie" "Bénin" "Burkina Faso" "Cap-Vert" "Côte d Ivoire" "Gambie" "Ghana" "Guinée" "Guinée-Bissau" "Liberia" "Mali" "Mauritanie" "Niger" "Nigeria" "Sénégal" "Sierra Leone" "Togo" "Burundi" "Comores" "Djibouti" "Érythrée" "Éthiopie" "Kenya" "Madagascar" "Malawi" "Maurice" "Mayotte" "Mozambique" "Ouganda" "Réunion" "Rwanda" "Seychelles" "Somalie" "Sud-Soudan" "Tanzanie" "Zambie" "Zimbabwe" "Angola" "Cameroun" "Centrafricaine (République)" "Congo" "Congo (rep)" "Gabon" "Guinée équatoriale" "Sao Tomé-et-Principe" "Tchad" "Afrique du Sud" "Botswana" "Lesotho" "Namibie" "Canada" "États-Unis" "Belize" "Costa Rica" "Guatemala" "Honduras" "Mexique" "Nicaragua" "Panama" "Salvador" "Antigua-et-Barbuda" "Aruba" "Bahamas" "Barbade" "Cuba" "Curaçao" "Dominicaine (République)" "Dominique" "Grenade" "Guadeloupe" "Haïti" "Jamaïque" "Martinique" "Porto Rico" "Sainte Lucie" "St Vincent-et-les-Grenadines" "St . Kitts-et-Nevis" "Trinité-et-Tobago" "Vierges (Îles)" "Argentine" "Bolivie" "Brésil" "Chili" "Colombie" "Équateur" "Guyana" "Guyane (française)" "Paraguay" "Pérou" "Surinam" "Uruguay" "Venezuela" "Arabie saoudite" "Arménie" "Azerbaïdjan" "Bahreïn" "Chypre" "Émirats arabes unis" "Georgie" "Irak" "Israël" "Jordanie" "Koweït" "Liban" "Oman" "Palestine (Territoires)" "Qatar" "Syrie" "Turquie" "Yémen" "Kazakhstan" "Kirghizistan" "Tadjikistan" "Turkménistan" "Ouzbékistan" "Afghanistan" "Bangladesh" "Bhoutan" "Pakistan" "Inde" "Iran" "Maldives" "Népal" "Sri Lanka" "Brunei" "Cambodge" "Indonésie" "Laos" "Malaisie" "Myanmar (Birmanie)" "Philippines" "Singapour" "Thaïlande" "Timor-Est" "Viêt Nam" "Chine" "Chine - Hong Kong" "Chine - Macao" "Corée du Nord" "Corée du Sud" "Japon" "Mongolie" "Taïwan" "Danemark" "Estonie" "Finlande" "Irlande" "Islande" "Lettonie" "Lituanie" "Norvège" "Royaume-Uni" "Suède" "Allemagne" "Autriche" "Belgique" "France (métropolitaine)" "Liechtenstein" "Luxembourg" "Monaco" "Pays-Bas" "Suisse" "Biélorussie" "Bulgarie" "Hongrie" "Moldavie" "Pologne" "Roumanie" "Russie" "Slovaquie" "Tchèque (République)" "Ukraine" "Albanie" "Andorre" "Bosnie-Herzégovine" "Croatie" "Espagne" "Grèce" "Italie" "Kosovo" "Macédoine" "Malte" "Monténégro" "Portugal" "Saint-Marin" "Serbie" "Slovénie" "Australie" "Fidji" "Guam" "Kiribati" "Marshall (Îles)" "Micronésie (États fédérés de)" "Nouvelle-Calédonie" "Nouvelle-Zélande" "Papouasie-Nouvelle-Guinée" "Polynésie française" "Salomon (Îles)" "Samoa occidentales" "Tonga" "Vanuatu"]

surface=[2382 1001 1760 447 266 1861 164 113 274 4 322 11 239 246 36 111 1240 1026 1267 924 197 72 57 28 2.2 23 118 1104 580 587 118 2 0.4 802 241 2.5 26 0.5 638 644 945 753 391 1247 475 623 342 2345 268 28 1 1284 1221 582 30 824 9971 9629 23 51 109 112 1958 130 76 21 0.4 0.2 14 0.4 111 0.3 49 0.8 0.3 1.7 28 11 1.1 9 1 0.5 0.4 5 0.3 2780 1099 8515 756 1139 284 215 90 407 1285 164 175 912 2150 30 87 0.7 9 84 70 438 22 89 18 10 310 6 11 185 784 528 2725 200 143 488 447 652 144 47 796 3287 1648 0.3 147 66 6 181 1905 237 330 677 300 0.7 513 15 332 9561 1.1 0.03 121 100 378 1564 36 43 45 338 70 103 65 65 385 243 450 357 84 31 552 0.2 2.6 0.001 42 41 208 111 93 34 313 238 17098 49 79 604 29 0.5 51 57 506 132 301 11 26 0.3 14 92 0.1 77 20 7741 18 0.5 0.7 0.2 0.7 19 271 463 4 29 2.8 0.7 12]

population=[38.3 84.7 6.5 33 0.6 34.2 10.9 9.6 18 0.5 21.1 1.9 26.1 11.8 1.7 4.4 15.5 3.7 16.9 174.9 13.5 6.2 6.2 10.9 0.8 0.9 5.8 89.2 44.2 22.5 16.3 1.3 0.22 24.3 36.9 0.8 11.1 0.09 10.4 9.8 49.1 14.2 13 21.6 21.5 4.7 4.4 71.1 1.6 0.8 0.2 12.2 53 1.9 2.2 2.4 35.3 316.2 0.33 4.7 15.4 8.6 117.6 6 3.9 6.3 0.09 0.1 0.35 0.25 11.3 0.15 10.3 0.07 0.11 0.41 10.4 2.7 0.38 3.6 0.17 0.11 0.05 1.3 0.11 41.3 11 195.5 17.6 48 15.8 0.8 0.24 6.8 30.5 0.6 3.4 29.7 30.1 3 9.4 1.1 1.1 9.3 4.5 35.1 8.1 7.3 3.5 4.8 4 4.4 2.2 21.9 76.1 25.2 17 5.7 8.1 5.2 30.2 30.6 156.6 0.7 190.7 1276.50 76.5 0.36 26.8 20.5 0.41 14.4 248.5 6.7 29.8 53.3 96.2 5.4 66.2 1.1 89.7 1360.70 7.2 0.6 24.7 50.2 127.3 2.8 23.4 5.6 1.3 5.4 4.6 0.32 2 3 5.1 64.1 9.6 80.6 8.5 11.2 63.9 0.04 0.54 0.04 16.8 8.1 9.5 7.3 9.9 4.1 38.5 21.3 143.5 5.4 10.5 45.5 2.8 0.07 3.8 4.3 46.6 11.1 59.8 1.8 2.1 0.45 0.6 10.5 0.03 7.1 2.1 23.1 0.9 0.16 0.11 0.06 0.11 0.26 4.5 7.2 0.28 0.58 0.19 0.1 0.27]

naissance=[26 25 22 22 22 34 19 39 43 21 37 43 33 38 38 42 46 35 50 40 38 38 37 45 32 29 38 34 36 35 40 11 32 44 45 17 36 19 45 37 40 44 33 47 39 47 38 45 32 37 38 51 22 24 28 27 11 13 22 16 32 26 19 24 20 18 14 11 13 12 12 13 22 13 17 13 26 15 11 11 16 19 13 15 16 19 26 15 15 19 22 21 26 24 20 18 14 21 21 14 19 14 12 16 13 31 22 27 19 14 21 33 12 25 17 34 23 27 31 22 21 37 21 22 30 22 19 22 24 17 17 25 21 26 18 18 21 10 12 33 17 12 13 13 15 10 8 27 10 10 11 11 16 14 10 10 12 13 12 8 9 12 13 10 11 6 10 10 12 9 9 11 10 9 13 10 10 11 13 9 8 10 10 9 9 14 11 10 12 9 9 9 11 13 21 21 28 31 24 17 14 31 17 34 28 27 31]

deces=[5 6 4 6 6 9 6 10 12 5 15 10 9 12 13 9 15 9 12 14 8 18 11 13 9 9 7 8 9 7 12 7 2 15 10 5 8 8 13 12 9 11 11 15 12 16 11 16 9 14 7 15 11 17 16 8 7 8 4 4 5 5 4 5 4 5 5 8 6 8 8 9 6 8 8 7 9 6 7 8 7 8 7 9 7 8 7 6 6 6 5 7 3 6 5 7 10 5 3 10 6 2 7 1 11 5 5 4 2 4 2 4 2 4 5 6 8 7 6 8 5 8 6 7 7 7 5 4 7 6 3 6 6 6 5 9 5 5 8 7 7 7 6 3 9 5 10 6 7 9 12 10 6 6 14 14 8 9 10 11 9 9 9 6 7 6 8 8 13 15 13 11 10 12 13 10 10 15 7 4 9 12 8 10 10 4 10 8 10 10 7 14 9 6 9 5 8 6 5 5 7 10 6 7 5 7 5]

homme=[76 69 73 69 65 60 73 58 55 70 49 57 60 55 52 59 52 60 57 51 62 45 55 51 59 59 59 61 59 62 54 70 76 49 57 77 61 68 53 53 59 54 55 50 53 47 56 48 62 51 64 49 56 47 48 61 79 76 71 77 68 71 75 71 74 67 74 73 72 73 76 72 70 71 70 77 61 71 79 76 72 70 72 71 77 72 65 71 76 70 72 63 76 70 72 67 73 72 73 71 71 75 76 76 70 66 80 72 74 77 74 71 77 72 71 61 64 66 64 61 65 59 69 65 65 65 72 73 66 71 77 61 68 66 72 63 66 80 71 65 70 73 81 79 65 78 79 65 76 78 71 78 78 81 69 68 79 80 80 78 78 78 79 79 78 79 79 80 67 71 71 67 72 70 64 72 75 66 74 79 73 74 79 79 79 67 73 79 72 77 82 72 76 80 67 75 62 70 67 74 79 61 74 66 72 70 70]

femme=[77 72 77 72 69 63 77 60 56 78 51 60 62 56 55 61 56 63 58 52 65 45 57 55 62 62 64 64 62 65 54 77 83 50 59 83 65 78 56 55 61 57 56 53 55 51 59 51 64 54 68 51 60 46 48 66 83 81 77 81 75 76 79 77 80 77 80 78 78 77 80 80 76 77 75 84 64 76 85 83 77 74 77 78 83 80 69 78 82 77 78 69 83 74 77 74 80 78 75 78 77 78 81 78 79 73 84 74 76 82 78 74 79 78 76 63 74 74 71 69 71 61 71 69 67 68 75 75 69 77 79 64 72 69 77 67 72 84 78 68 76 77 86 86 73 84 86 72 83 82 81 83 83 84 79 79 83 84 84 83 83 83 85 84 83 85 83 85 78 78 78 75 81 77 76 79 81 76 80 85 78 80 85 83 85 71 77 83 77 83 86 77 83 84 72 81 67 74 68 81 83 66 78 69 74 75 73]

Correction

a - Saisie Affichage

i=input("Index du pays ? ")
disp(pays(i),"Pays choisi : ")
disp(surface(i),"Surface en milliers de km^2 : ")
disp(population(i),"Nombre habitants en millions : ")
disp(population(i)*10^3/surface(i),"Densité du pays : ")

b.1) Calculs de sommes

disp(sum(surface),"Surface totale : ")
disp(sum(population),"Population totale : ")
disp(sum(population)*10^3/sum(surface),"Densité moyenne : ")

b.2) Calculs de sommes sur des matrices extraites - Syntaxe conditionnelle

test=1
while test==1
    n1=input("Entrer indice inférieur : ")
    n2=input("Entrer indice supérieur : ")
    disp(sum(surface(n1:n2)),"Surface = ")
    disp(sum(population(n1:n2)),"Population =")
    disp(sum(population(n1:n2)*10^3/sum(surface(n1:n2))),"Densité =")
    r=input("Continuez O/N ?")
    if (r=="N")|(r=="n") then
        test=0
    end
end

b.3) Calcul sur l'union européenne

UE=[150 151 152 153 155 156 158 159 160 161 162 163 165 167 170 171 173 174 176 177 182 184 185 188 193 190 183 103]
S=sum(surface(UE))
P=sum(population(UE))
D=P*10^3/S
disp(S,"Surface = ")
disp(P,"Population = ")
disp(D,"Densité = ")

c. 1. à 3.

M1=mean(homme)
M2=mean(homme .^2)
V=M2-M1^2
Sigma=sqrt(V)
Me=median(homme)
disp(M1,"Moyenne = ")
disp(Me,"Mediane = ")
disp(Sigma,"Ecart-type = ")
disp(st_deviation(homme),"Ecart-type estimé")

c 4 à 7

min_femme=min(femme)
max_femme=max(femme)
ind_min=find(femme==min_femme)
ind_max=find(femme==max_femme)
disp(pays(ind_min),"Le(s) Pays",min(femme),"espérance minimale")
disp(pays(ind_max),"Le(s) Pays",max(femme),"espérance maximale")
effectif_partiel=tabul(femme)
disp(tabul(femme))
effectif_maximum=max(effectif_partiel(:,2))
rang_mode=find(effectif_partiel(:,2)==effectif_maximum)
mode_femme=effectif_partiel(rang_mode,1)
disp(mode_femme,"Mode Femme =")
liste_pays_mode=find(femme==mode_femme)
disp(pays(liste_pays_mode))

c 8 Tri et recherche

disp("Tri des valeurs dans ordre croissant")
tri=gsort(femme,'g','i')
disp(tri)
pause
dim_tri=size(tri)
disp(dim_tri,"dimension de la matrice")
pause
nb_decile10=floor(0.1*dim_tri(2))
disp(nb_decile10,"Indice du 1er decile")
d10=tri(nb_decile10)
disp(d10,"premier decile")
nb_decile90=floor(0.9*dim_tri(2))
disp(nb_decile90,"Indice du 9ème decile")
d90=tri(nb_decile90)
disp(d90,"neuvième decile")
pause
disp("pays où espérance de vie la plus faible")
liste_indice_decile=find(femme<=d10)
for j=liste_indice_decile
    disp(femme(j),pays(j))
end
pause
disp("pays où espérance de vie la plus forte")
liste_indice_decile=find(femme>=d90)
for j=liste_indice_decile
    disp(femme(j),pays(j))
end

Chapitre 3 - Corrélation

Ajustement Affine

plot2d(pop_france(:,1),pop_france(:,2),style=-1)
X=pop_france(1:65,1:1)
Y=pop_france(1:65,2:2)
EX=mean(X)
EY=mean(Y)
covXY=mean(X .*Y)-EX*EY
VX=mean(X .^2)-EX^2
a=covXY/VX
b=EY-a*EX
pop2030=a*2030+b
disp(pop2030,"pop 2030 = ")
pop2050=a*2050+b
disp(pop2050,"pop 2050 = ")
an=[1945:2050]
Estim=a*an+b
plot2d(an,Estim,style=5)

Ajustement Racine Carrée

plot2d(pop_france(:,1),pop_france(:,2),style=-1)
T=sqrt(pop_france(71:190,1:1)-1820)
Y=pop_france(71:190,2:2)
[cv,m]=corr(T,Y,1)
VT=mean(T .^2)-m(1)^2
a=cv/VT
b=m(2)-a*m(1)
an=[1820:2009]
Estimation=a*sqrt(an-1820)+b
plot2d(an,Estimation,style=5)
disp(a*sqrt(2009-1820)+b,"population 2009 : ")

Ajustement Exponentielle

Début du programme uniquement

X=pop_france(1:65,1:1)
Y=pop_france(1:65,2:2)
an=[1946:2009]
YC=gsort(Y,'g','i')
for k=[1:64]
    T(k)=(YC(k+1)-YC(k))/YC(k)
end
[cv,m]=corr(an,log(T),1)
VX=mean(an .^2)-m(1)^2
a=cv/VX
b=m(2)-a*m(1)
plot2d(an,T,style=-1)

Exercice type concours

function rho=calcul_corr(a,n)
    nb_sim=100000
    R=grand(nb_sim, n, "unf", 0, a)
    couple=[min(R, "c"), max(R, "c")]
    moy_U=mean(couple(:,1))
    moy_V=mean(couple(:,2))
    var_U=mean(couple(:,1) .^2)-moy_U^2
    var_V=mean(couple(:,2) .^2)-moy_V^2
    covariance=mean(couple(:,1) .*couple(:,2))-moy_U*moy_V
    rho=covariance/sqrt(var_U*var_V)
endfunction 
for n=[2, 3, 4]
    for a=[1,5,10]
        disp(calcul_corr(a,n),"rho=",a,"a=",n,"n=")
    end
end

Correction DL et DS

DS n°3

Exo 1 - q4

Soit X une VAR qui suit une loi de Poisson de paramètre $\lambda$ et de fonction de répartition $F$. Soit $r$ un réel élément de $]0;1[$. Compléter le programme suivant qui détermine la valeur $n$ telle que $F(n)<r$ et $F(n+1)>r$. On exprimera au préalable $P(X=n+1)$ en fonction de $P(X=n)$.

Programme 1

Vous préciserez le rôle de P dans le programme

lambda=input("lambda = ")
r=input("r = ")
n=0
P=exp(-lambda)
F=P
While ...
   n=n+1
   P=P*lambda/n
   F=F+...
end   
disp(n)   

Programme 2

lambda=input("lambda = ")
r=input("r = ")
P(1)=exp(-lambda)
for k=[2:100]
    P(k)=P(k-1)*lambda/(k-1)
end
F=cumsum(P)
n=length(find(F<=r))
disp(n-1)

On rappelle que l'instruction cumsum(P) fait la somme cumulée des coefficients de P. L'instruction length donne la longueur de la matrice (expression simplifiée de size). Expliquez pas à pas ce que fait le programme.

Exo 2 - q1

On considère le script suivant

n=input("n = ")
X=0;Y=0;rang=0
while (X==0)|(Y==0)
   rang=rang+1
   tirage=floor(n*rand())+1
   disp(tirage)
   if (tirage==1)&(X==0) then X=rang;end
   if tirage==2&(Y==0) then Y=rang;end
end
disp(X);disp(Y)   
  1. Dans cette question n=10. On obtient la suite des valeurs de la variable tirage: 10. 8. 7. 7. 6. 1. 3. 10. 9. 4. 6. 3. 1. 5. 5. 8. 4. 6. 1. 7. 7. 7. 2. Quelles sont les valeurs affichées par les variables X et Y
  2. Que simule la variable tirage?
  3. Expliquer le fonctionnement de la boucle while…end
info/2/fichiers_sources.txt · Dernière modification : 2020/05/10 21:19 de 127.0.0.1