def comStatisticUnc(self): value = self.comp_value count = np.count_nonzero(value) std = Unc.stdev(value) mean = Unc.mean(value) meanAvg = std / math.sqrt(count) return Ucom(mean, meanAvg, self.name, self.dep)
from unc import Unc R1 = Unc(3, 0.5) R2 = Unc(2, 0.2) R3 = Unc(1, 0.2) R4 = Unc(1, 0.1) print(id(R1), id(R2), id(R3), id(R4)) K3 = R2+R1+R4 print(K3) #print(R1+R2+R3)
import numpy as np from unc import Unc import math a = Unc(3, 0.5) b = Unc(2, 0.7) print('\nUncertainty value with constant calculation:') print("NOTE: By default the value in parenthesis represents the absolute uncertainty\n") input("Enter any key to continue ...........") # ######## Constant calculation with addition ################## # ########################### Addition Calculation ################## print('Value and uncertainty is:', a) print('Now if we Add(+) pi=3.14 Constant right side of the calculation, example: Unc(3, 0.5) + Unc(math.pi)') c = a + Unc(math.pi) print(c) input("Enter any key to continue ...........") print('\nNow if we Add(+) pi=3.14 Constant left side of the calculation, example: Unc(math.pi) + Unc(3, 0.5)') d = Unc(math.pi) + a print(d) ################################################################# input("Enter any key to continue ...........\n") print('Now if we Subtract (-) pi=3.14 Constant right side of the calculation, example: Unc(3, 0.5) - Unc(math.pi)') # ######## Constant calculation with subtraction ################## c = a - Unc(math.pi) print(c) print('Now if we Subtract (-) pi=3.14 Constant left side of the calculation, example: Unc(math.pi) - Unc(3, 0.5)') d = Unc(math.pi) - a
from unc import Unc Ug = 0 R2 = 1e3 R3 = 1e3 R4 = 1.001e3 U0 = 5 u_R2 = 5 u_R3 = 5 u_R4 = 1 u_U0 = 1.00 u_Ug = 0.01 R2 = Unc(R2, u_R2) R3 = Unc(R3, u_R3) R4 = Unc(R4, u_R4) U0 = Unc(U0, u_U0) Ug = Unc(Ug, u_Ug) I2 = U0 / (R3 + R4) I1 = (I2 * R4 + Ug) / R2 R1 = U0 / I1 - R2 print(R1)
import numpy as np from unc import Unc import math atext = """ ----------- Operations with Matrix ----------------- """ print(atext) # ################ MATRIX ADDITION EXAMPLE 1 ################################ n = 3 size = np.ones((n, 3)) print("\nMatrix 1:\n") A = Unc(np.matrix('11,12,13;21,22,23;31,32,44'), size, '') # Size variable assume as uncertainty values of the matrix # A = Unc(np.matrix('11,12,13;21,22,23;31,32,44'), size, 'R') to see relative uncertainty print("\nMatrix 2:\n") B = Unc(np.matrix('10,20,30;40,50,60;70,80,90'), size, '') # Matrix B print( "NOTE:By default the value inside parenthesis represents the absolute uncertainty\n" ) print('\nNow perform Matrix addition calculation.') input("Enter any key to view result ...........\n") C = A + B # Sum Up print("Result:\n", C) ########################################################################### print('\nNow try with different uncertainty value') # ################ MATRIX ADDITION EXAMPLE 2 ################################ input("Enter any key to continue ...........")
# ####################################################### # ================ Perform basic Calculation ======= # ####################################################### import numpy as np from unc import Unc import math x = 3 # value 1 y = 2 # value 2 x_u = 0.5 # uncertainties 1 x_y = 0.7 # uncertainties 2 a = Unc(x, x_u) # a = Unc(x, x_u,'R','category name','departments') to see relative uncertainty b = Unc(y, x_y) print('\nPerform Basic Calculation') print("NOTE: By default the value in parenthesis represents the absolute uncertainty\n") input("Enter any key to continue ...........") # ########################### Addition Calculation ################## print('First value is:', x, 'And Uncertainty is:', x_u,'Second value is:', y, 'And Uncertainty is:', x_y) print('\nPerform Addition calculation:') Addition = a+b print(Addition) ################################################# # ######## Subtraction Calculation ############## print('\nPerform Subtraction calculation:') input("Enter any key to continue ...........") Subtraction = a-a print(Subtraction) #################################################
def __str__(self): comp_value = rmParen(self.comp_value) comp_unc = rmParen(self.comp_unc) Unc.nameANDdep(self.name, self.dep) return "%s[%s]" % (comp_value, comp_unc)
import numpy as np from unc import Unc import math a = Unc(30, 0.2) # ######## trigonometric calculation on degree ################## print('By default trigonometric calculations are performed in "Radian". If we want to get result in "Degree" than we need to call degree function\n') print('Let Value and uncertainty is :', a) print("NOTE:The value in parenthesis represents the absolute uncertainty\n") input("Enter any key to continue ...........\n") print('Lets perform sin calculation') sin = Unc.degree(a, 'sin') print(sin) input("\nEnter any key to continue ...........\n") print('Lets perform cos calculation') cos = Unc.degree(a, 'cos') print(cos) input("\nEnter any key to continue ...........\n") print('Lets perform tan calculation') tan = Unc.degree(a, 'tan') print(tan) input("\nEnter any key to continue ...........\n") print('Lets perform cot calculation') cot = Unc.degree(a, 'cot') print(cot) #################################################################
import numpy as np from unc import Unc import math atext = """ ----------- Operations with Matrix ----------------- """ print(atext) # ################ MATRIX MULTIPLICATION EXAMPLE 1 ################################ n = 3 size = np.ones((n, 3)) print('Lets perform Matrix Calculation.') print("\nMatrix 1:\n") A = Unc(np.matrix('11,12,13;21,22,23;31,32,44'), size) # Size variable assume as uncertainty values of the matrix print("\nMatrix 2:\n") B = Unc(np.matrix('10,20,30;40,50,60;70,80,90'), size) # Matrix B print('\nNow perform Matrix multiplication calculation.') input("\nEnter any key to view result ...........\n") C = A * B # Sum Up print("\nResults:\n", C) print( "NOTE:By default the value inside parenthesis represents the absolute uncertainty\n" ) ###########################################################################
import numpy as np from unc import Unc import math atext = """ ----------- Operations with Arrays ----------------- """ print(atext) # ################ Statical Uncertainty Example ################################ print('\nLet’s assume that length of an object has measured five times') a = np.array([72, 77, 82, 85, 88, 90, 86, 70, 91, 95]) print('\n', a) result = Unc(a, '', '', 'Math', 'Gp1') # Size variable assume as uncertainty values of array input("\nEnter any key to see results ...........") print(result.statUnc(), '\n') # ############################################################################################ # ################ Sum up Uncertainty Example ################################ input("\nEnter any key to continue ...........") print('Lets sum up multiple uncertainty') a = np.array([1, 2, 3, 4, 5, 6, 7, 7, 9, 10]) b = np.array([0.005, 0.02, 0.003, 0.04, 0.005, 0.06, 0.07, 0.07, 0.09, 0.02]) print("\nValues and Uncertainties are:\n", a, '\n', b) A = Unc(a, b) # Size variable assume as uncertainty values of array A = Unc(a, b, '') # Size variable assume as uncertainty values of array input("\nEnter any key to see results ...........") print(' Results is:', A.sum())