написал функции для расчета абсолютной погрешности
This commit is contained in:
34
lab2/AbsoluteMeasurementErrors.py
Normal file
34
lab2/AbsoluteMeasurementErrors.py
Normal file
@@ -0,0 +1,34 @@
|
||||
def get_accuracy(x):
|
||||
x_str = str(x)
|
||||
acc = 0
|
||||
|
||||
if "." in x_str:
|
||||
acc = len(x_str) - x_str.find(".") - 1
|
||||
|
||||
return acc
|
||||
|
||||
|
||||
def get_error(x):
|
||||
acc = get_accuracy(x)
|
||||
return 1 / 10**acc / 2
|
||||
|
||||
|
||||
def sum_error(*values):
|
||||
return sum([get_error(value) for value in values])
|
||||
|
||||
|
||||
def product_error(*values):
|
||||
p = 1
|
||||
s = 0
|
||||
for value in values:
|
||||
p *= value
|
||||
s += get_error(value) / abs(value)
|
||||
return p * s
|
||||
|
||||
|
||||
def frac_error(a, b):
|
||||
return abs(a / b) * (get_error(a) / abs(a) + get_error(b) / abs(b))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_error(1)
|
||||
Reference in New Issue
Block a user