G1909 - Une convexit´e tr`es probable ?
On choisit au hasard quatre points A,B,C,D ind´ependamment les uns des autres, dans les quadrants respectifs Nord Ouest, Nord Est, Sud Est et Sud Ouest d’un carr´e dont les sommets ont pour coordonn´ees (–1,1), (1,1), (1,–1) et (–1,–1). Est-il exact que la probabilit´e que le quadrilat`ere ABCD soit convexe est sup´erieure `a 90% ?
Solution proppos´ee par O. Housseine
Les coordonn´ees (x, y) des pointsA,B,C etD sont des variables al´eatoires qui suivent un loi uniforme continue de param`etres 0 et ±1 (selon le quad- rant).
On pourra ainsi r´ealiser une simulation en g´en´erant un ´echantillon de taille N des coordonn´es des pointA,B,CetD. Ensuite, on calculera pour chaque observation les angles \DAB, ABC[, BCD\ et \CDA afin de d´eterminer si le quadrilat`ere ABCD est convexe.
Pour N assez grand, la probabilit´ep que le quadrilat`ere ABCD soit convexe est calcul´e parp=n/N avecnle nombre d’observations pour lesquels ABDC est convexe.
Le tableau suivant r´esume les r´esultats obtenus:
N p
10 0.800
100 0.910
1000 0.886
10000 0.908
100000 0.910 1000000 0.909 10000000 0.909
On peut donc conclure que la probabilit´e que ABCD soit convexe est sup´erieure
`a 90% (p≈91%).
Ci-dessous le code Python utilis´e pour g´en´erer ces r´esultats:
# −∗− coding : utf −8 −∗−
import numpy as np
import matplotlib . pyplot as p l t import pandas as pd
def b u i l d p o i n t s ( ) :
”””c o n s t r u i t l e s p o i n t s A,B,C e t D a l e a t oi r e m e nt
Returns :
za ( complex ) : a f f i x e de A zb ( complex ) : a f f i x e de B zc ( complex ) : a f f i x e de C zd ( complex ) : a f f i x e de D
”””za = np . random . uniform ( −1 ,0) + 1 j ∗ np . random . uniform (0 ,+1) zb = np . random . uniform (0 ,+1) + 1 j ∗ np . random . uniform (0 ,+1) zc = np . random . uniform (0 ,+1) + 1 j ∗ np . random . uniform ( −1 ,0) zd = np . random . uniform ( −1 ,0) + 1 j ∗ np . random . uniform ( −1 ,0)
return za , zb , zc , zd def a n g l e v e c t o r ( z1 , z2 ) :
”””c a l c u l e angle o r i e n t e ( z1 , z2 ) en degree entre deux v e c t e u r d a f f i x e z1 , z2
Args :
z1 ( complex ) : a f f i x e du premier v e c t e u r z2 ( complex ) : a f f i x e du deuxieme v e c t e u r Returns :
res ( f l o a t ) : angle entre 0 e t 360 degree
”””t = np . angle ( z2 ) − np . angle ( z1 ) i f t < 0 :
t += 2∗np . pi r e s = t ∗180/np . pi return r e s
def i s c o n v e x ( za , zb , zc , zd ) :
”””Determine s i l e q u a d r i l a t e r e ABCD e s t convexe Args :
za ( complex ) : a f f i x e de A zb ( complex ) : a f f i x e de B zc ( complex ) : a f f i x e de C zd ( complex ) : a f f i x e de D Returns :
conv ( b oo l ) : True s i ABCD e s t convexe
”””zab = zb−za zbc = zc−zb zcd = zd−zc zda = za−zd
t a = a n g l e v e c t o r (−zda , zab ) t b = a n g l e v e c t o r (−zab , zbc ) t c = a n g l e v e c t o r (−zbc , zcd )
t d = a n g l e v e c t o r (−zcd , zda )
conv = np . array ( [ t a , t b , t c , t d ] ) >=180 conv = not( np .sum( conv ) ) > 0
return conv
def plot ABCD ( za , zb , zc , zd ) :
”””Trace l e q u a d r i l a t e r e ABCD Args :
za ( complex ) : a f f i x e de A zb ( complex ) : a f f i x e de B zc ( complex ) : a f f i x e de C zd ( complex ) : a f f i x e de D Returns :
conv ( b ool ) : True s i ABCD e s t convexe
”””
pt = np . array ( [ za , zb , zc , zd , za ] ) xp = pt . r e a l
yp = pt . imag p l t . c l o s e ( ’ a l l ’ )
f i g , ax = p l t . subplots ( ) ax . p l o t ( xp , yp )
ax . g r i d ( True )
ax . s e t x l i m ([ −1 ,1]) ax . s e t y l i m ([ −1 ,1]) ax . s e t x l i m ([ −1 ,1])
f o r x , y , s in zip( xp [ : − 1 ] , yp [ : − 1 ] , [ ’A ’ , ’B ’ , ’C ’ , ’D’ ] ) : p l t . annotate ( s , ( x , y ) )
p l t . margins ( 0 . 0 2 )
def ABCD convex(n ) :
”””c a l c u l l a p r o b a b i l i t e que l e q u a d r i l a t e r e ABCD e s t convexe Args :
n( i n t ) : T a i l l e de e c h a n t i l l o n Returns :
pr ( f l o a t ) : p r o b a b i l i t e que ABCD e s t convexe
”””
r e s = 0 .
f o r i in range(n ) :
za , zb , zc , zd = b u i l d p o i n t s ( )
conv = i s c o n v e x ( za , zb , zc , zd ) i f conv :
r e s += 1.0 pr = r e s /n
return pr
i f name == ” ma in ” :
za , zb , zc , zd = b u i l d p o i n t s ( ) plot ABCD ( za , zb , zc , zd )
a = i s c o n v e x ( za , zb , zc , zd ) n = 100
p = ABCD convex(n)
n l i s t = [10∗∗ i f o r i in range( 1 , 8 ) ] p r l i s t = [ ]
f o r nval in n l i s t :
p r l i s t . append (ABCD convex( nval ) )
df = pd . DataFrame ({’n ’ : n l i s t , ’ prob ’ : p r l i s t })