1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #Déclaration des variables sous forme de vecteurs de longueur n, générées aléatoirement avec la loi normale
n<-10000 #nombre de valeurs simulées
CH2.GN<-c(rnorm(n, 6.0294, 0.005812))
CH4.GX<-c(rnorm(n, 63.1148, 0.005316))
CH4.x<-c(rnorm(n, -0.0068, 0.006393))
CH4.y<-c(rnorm(n, 0.0133, 0.005964))
P1.GN<-c(rnorm(n, 8.2032, 0.002065))
P2.GG<-c(rnorm(n, 48.6313, 0.010953))
P2.GN<-c(rnorm(n, 48.6536, 0.011224))
P2.x<-c(rnorm(n, 0.0022, 0.004436))
P2.y<-c(rnorm(n, 0.0199, 0.006347))
P3.GG<-c(rnorm(n, 43.0018, 0.004604))
P4.GG<-c(rnorm(n, 43.0479, 0.004694))
# Fonction qui decrit l'excentration en fonction de l'angle d en radian
A<-(CH2.GN + P1.GN)/2
B<-(P2.GG + (P3.GG+P4.GG)/2 )/4
fjeu=function(d){
j<-sqrt(((A*cos(d)+sqrt(P2.x^2+P2.y^2)*cos(atan2(P2.y,P2.x)-asin(A*sin(d)/B)))-CH4.x)^2+((A*sin(d)+sqrt(P2.x^2+P2.y^2)*sin(atan2(P2.y,P2.x)-asin(A*sin(d)/B)))-CH4.y)^2)-A
return(j)
}
#Recherche de l'angle qui maximise la fonction excentration
# Création d'un vecteur a des angles de 0 à 360° (en radians)
angles <- seq(0, 2*pi, by = (2*pi)/360)
# Création d'une matrice avec 361 colonnes, n lignes, avec un angle par colonne
matjeu <- t(matrix(rep(angles), nr=length(angles), nc=n))
# Calcul de l'excentration pour chaque angle de la matrice matjeu
exc_max<-apply(apply(matjeu, 2, fjeu), 1, max)
# Calcul de Jeux
JR3<-(CH4.GX-P1.GN-CH2.GN-P2.GN)/2
JR3avExc = JR3-exc_max
# Représentation graphique
TI=0.01 # Tolérance inf
hist(JR3avExc, col="lightblue",border="lightblue", xlim=c(0,0.15), main="Jeu JR3-EMP1", probability = TRUE, breaks=ceiling(sqrt(n)))
#lines(density(JR3avExc), col="orange") courbe de densité de l'histogramme
abline(v=TI,col="darkorange")
xbj=mean(JR3avExc)
sj=sd(JR3avExc)
# Tracé loi Normale
xloin=seq(from=xbj-3.5*sj , to=xbj+3.5*sj, length.out=100)
yloin=dnorm(xloin, mean=xbj, sd=sj)
lines(xloin, yloin, col="darkred", lty=3) |