-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
55 lines (43 loc) · 1.04 KB
/
utils.py
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
53
54
# utils.py
# Math library
# Author: Sébastien Combéfis
# Version: February 8, 2018
import math
from collections import namedtuple
def fact(n):
if n<0:
raise ValueError
if n<2:
return 1
else:
return n*fact(n-1)
def roots(a, b, c):
delta = (b ** 2) - (4 * a * c)
if a == 0:
print("veuilliez donner une equaiton du second degré")
if delta < 0:
return ("","")
if delta > 0:
x1 = float((- b - math.sqrt(delta)) / (2*a))
x2 = float((- b + math.sqrt(delta)) / (2*a))
return ("{}","{}".format(x1, x2))
if delta == 0:
x1 = (-b - math.sqrt(delta)/(2*a))
return ("{}".format(x1))
def ff(x):
return x
def gg(x):
return x*2
def integrate(function, lower, upper):
a = lower
b = upper
n = 100000 #nbr de pas
h = (b - a) / n
result = 0
for i in range(0,n-1):
result += h * function(a + h*i)
return result
if __name__ == '__main__':
print(fact(5))
print(roots(2, 2, 0))
print(integrate(ff, 0, 1))