-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeasurement.py
38 lines (37 loc) · 1.13 KB
/
measurement.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
class Measurement:
def __init__(self, x, delta_x):
self.val = x
self.delta = delta_x
def __add__(self, o):
ret = Measurement(self.val + o.val, self.delta + o.delta)
return ret
def __sub__(self, o):
ret = Measurement(self.val - o.val, self.delta + o.delta)
return ret
def __mul__(self, o):
if(type(o) == type(self)):
ret = Measurement(self.val * o.val, self.delta*o.val + self.val*o.delta)
else:
ret = Measurement(self.val*o, self.delta*o)
return ret
def __truediv__(self, o):
ret = Measurement(self.val / o.val, (self.delta*o.val + self.val*o.delta)/(o.val**2))
return ret
def __pow__(self, n):
ret = Measurement(self.val**n, (self.val**(n - 1))*n*self.delta)
return ret
def __str__(self):
return f'{self.val} ± {self.delta}'
def __repr__(self):
return f'{self.val} ± {self.delta}'
# d = Measurement(9.7*(10**-4), 0.00005)
# b = Measurement(0.02475, 0.00005)
# d3 = d**3
# w = Measurement(3.716, 9.81*10**(-5))
# p = d3*b*(2.86)
# E = w*4
# E /= p
# E *= 1/(10**10)
#
#
# print(E)