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
| ##1
def polyplus(a,b,c):
delta = complex(b**2 - 4*a*c) #le discriminant
sol1 = complex((b**2 - np.sqrt(delta)) / (2*a)) #solution 1
sol2 = complex((b**2 + np.sqrt(delta)) / (2*a)) #solution 2
if sol1.real > 0 and sol1.imag == 0 : #la solution 1 doit être réelle positive
if sol2.imag == 0 and sol2.real > 0 and sol2.real > sol1.real : #La solution 2 doit être réelle positive aussi
return (sol1.real , sol2.real) #Affichage selon l'ordre croisant
if sol2.imag == 0 and sol2.real > 0 and sol2.real < sol1.real :
return (sol2.real , sol1.real)
else:
return (sol1.real , None)
elif sol1.real <= 0 :
if sol2.real > 0 and sol2.imag == 0:
return (sol2.real, None)
else:
return None
#Evaluation des valeurs données:
print (polyplus(1,-5,2))
print (polyplus(1,-1,-2))
print (polyplus(1,3,2))
print (polyplus(1,4,7))
##2
def polycont(a,b,c):
if None in polycont(a,b,c)[1]:
return 1
print (polycont(1,-5,2))
#print (polycont(1,-1,-2))
print (polycont(1,3,2))
#print (polycont(1,4,7)) |
Partager