def get_cpeParams(freq_min, freq_max, m, perDecade=3): """ Calculates the parameters required to create a sufficiently accurate Constant Phase Element (CPE) from the given parameters. Returns (pts, k, y_theta) where: pts: an array of frequencies at which to place RC elements k: a parameter that controls multiplicity y_theta: another parameter, not sure of its exact definition """ # Extend the range so no funny stuff happens at the endpoints freq_min /= 1000 freq_max *= 1000 # Calculate the number of elements to place in this range numPts = (math.log10(freq_max) - math.log10(freq_min)) * perDecade # Calculate the frequency scaling factor k_f = math.exp((math.log(freq_max) - math.log(freq_min)) / numPts) # Generate the x positions for cpe elements pts = [] for i in range(int(numPts) + 1): pts.append(freq_min * math.pow(k_f, i)) # Determine k - the multiplicity factor k = math.pow(k_f, 1 / m) # k gets used here to create the y_theta variables # which are passed to generate_fracpoleSubcircuit and used # to choose the value of capacitance in each RC branch. y_theta = ((math.pi / (m * math.log(k))) * mpmath.sec(0.5 * math.pi * (1 - (2 / m)))) return (pts, y_theta)
def random_trig(x): print('Random Value between -pi and pi is:', x) print('FINDING VALUES FOR:') print('sin(t): ', math.sin(x)) print('cos(t): ', math.cos(x)) print('tan(t): ', math.tan(x)) print('sec(t): ', mpmath.sec(x)) print('-sin(t): ', -math.sin(x)) print('-cos(t): ', -math.cos(x)) print('-tan(t): ', -math.tan(x)) print('sin(-t): ', math.sin(-x)) print('cos(-t): ', math.cos(-x)) print('tan(-t): ', math.tan(-x)) print('sin(t)/cos(t): ', math.sin(x) / math.cos(x)) print('2sin(t/2)cos(t/2):', 2 * math.sin(x / 2) * math.cos(x / 2)) print('sin^2(t): ', math.pow(math.sin(x), 2)) print('1-cos^2(t) ', 1 - math.pow(math.cos(x), 2)) print('(1-cos(2t))/2: ', (1 - math.cos(2 * x)) / 2) print('1/cos(t): ', 1 / math.cos(x))
def SEC(self, a): x = Argument(int32_t) y = Argument(int32_t) try: with Function("Secant", (x, y), int32_t) as asm_sec: reg_x = GeneralPurposeRegister32() LOAD.ARGUMENT(reg_x, x) SEC(reg_x) RETURN(reg_x) code_sec = asm_sec.finalize(abi.detect()).encode().load() except: code_sec = round(mpmath.sec(a), 4) return (code_sec) return (code_sec(a))
def trigOfT(t): # computes values asked for (a through p) in the lab and appends to list trig = [] trig.append(math.sin(t)) trig.append(math.cos(t)) trig.append(math.tan(t)) trig.append(float(mpmath.sec(t))) trig.append(-math.sin(t)) trig.append(-math.cos(t)) trig.append(-math.tan(t)) trig.append(math.sin(-t)) trig.append(math.cos(-t)) trig.append(math.tan(-t)) trig.append(trig[0] / trig[1]) l1 = float((math.sin(t / 2))) l2 = float((math.cos(t / 2))) trig.append(float(2 * (l1 * l2))) trig.append(trig[0] * trig[0]) trig.append(1 - (trig[1] * trig[1])) trig.append((1 - math.cos(2 * t)) / 2) trig.append(1 / trig[1]) return trig
def set_standard_latitude(self, val): self.cos_standard_latitude = math.cos(val) self.sec_standard_latitude = mpmath.sec(val)
def d(x): return mpmath.sec(x)
# -*- coding: utf-8 -*- """ Created by libsedmlscript v0.0.1 """ from sed_roadrunner import model, task, plot from mpmath import sec #---------------------------------------------- sec(0.5)
def eval(self, z): return mpmath.sec(z)
def subcircuit_displacement(self, fmin=1e-6, fmax=1e6, elementsPerDecade=3, name='displacement', bypassRes=1e10): """ Generates the ngspice compatible subcircuit named fracpole ready for inclusion into a spice file """ # Extend freq range so no funny business appears fmin /= 1000.00 fmax *= 1000.00 print(fmin) print(fmax) cpe_mag = self.parameterSet.displacement_mag() cpe_slope = self.parameterSet.displacement_slope() m = self.parameterSet.displacement_m() # Calculate the number of elements to place in this range numPts = (math.log10(fmax) - math.log10(fmin)) * elementsPerDecade # Calculate the frequency scaling factor k_f = math.exp((math.log(fmax) - math.log(fmin)) / numPts) # Generate the frequency positions for the cpe branches pts = [] for i in range(int(numPts) + 1): pts.append(fmin * math.pow(k_f, i)) # Determine k - the multiplicity factor k = math.pow(k_f, 1 / m) y_theta = ((math.pi / (m * math.log(k))) * mpmath.sec(0.5 * math.pi * (1 - (2 / m)))) out = [] out.append("****************************************") out.append("* Fracpole/CPE start *") out.append("****************************************") fracpoleElements = [] for point in pts: omega = 2 * math.pi * point Z = cpe_mag * math.pow(point, cpe_slope) R = Z C = math.pow((R / (y_theta * Z)), m) / (omega * R) fracpoleElements.append({'frequency': point, 'R': R, 'C': C}) out.append(".SUBCKT " + name + " a b") for num, facpoleElement in enumerate(fracpoleElements): out.append("R" + str(num) + " a " + str(num + 1) + " " + str(facpoleElement['R'])) out.append("C" + str(num) + " " + str(num + 1) + " b " + str(facpoleElement['C'])) out.append("R" + str(num + 1) + " a b " + str(bypassRes)) out.append(".ENDS " + name) return out
'mpc': ['primitive', [lambda x, y: mp.mpc(x, y[0]), None]], # 'sqrt': ['primitive', [lambda x, y: mp.sqrt(x), None]], 'cbrt': ['primitive', [lambda x, y: mp.cbrt(x), None]], 'root': ['primitive', [lambda x, y: mp.root(x, y[0]), None]], # y's root 'unitroots': ['primitive', [lambda x, y: Vector(mp.unitroots(x)), None]], # 'hypot': ['primitive', [lambda x, y: mp.hypot(x, y[0]), None]], # sqrt(x**2+y**2) # 'sin': ['primitive', [lambda x, y: mp.sin(x), None]], 'cos': ['primitive', [lambda x, y: mp.cos(x), None]], 'tan': ['primitive', [lambda x, y: mp.tan(x), None]], 'sinpi': ['primitive', [lambda x, y: mp.sinpi(x), None]], #sin(x * pi) 'cospi': ['primitive', [lambda x, y: mp.cospi(x), None]], 'sec': ['primitive', [lambda x, y: mp.sec(x), None]], 'csc': ['primitive', [lambda x, y: mp.csc(x), None]], 'cot': ['primitive', [lambda x, y: mp.cot(x), None]], 'asin': ['primitive', [lambda x, y: mp.asin(x), None]], 'acos': ['primitive', [lambda x, y: mp.acos(x), None]], 'atan': ['primitive', [lambda x, y: mp.atan(x), None]], 'atan2': ['primitive', [lambda x, y: mp.atan2(y[0], x), None]], 'asec': ['primitive', [lambda x, y: mp.asec(x), None]], 'acsc': ['primitive', [lambda x, y: mp.acsc(x), None]], 'acot': ['primitive', [lambda x, y: mp.acot(x), None]], 'sinc': ['primitive', [lambda x, y: mp.sinc(x), None]], 'sincpi': ['primitive', [lambda x, y: mp.sincpi(x), None]], 'degrees': ['primitive', [lambda x, y: mp.degrees(x), None]], #radian - >degree 'radians': ['primitive', [lambda x, y: mp.radians(x), None]], #degree - >radian
def precompute_values(self): self.n = (math.log(math.cos(self.phi1) * mpmath.sec(self.phi2)))/ math.log(math.tan(math.pi/4 + self.phi2/2) * mpmath.cot(math.pi/4 + self.phi1/2)) if self.n == 0.0000: self.n = 0.00001 self.F = (math.cos(self.phi1) * math.pow(math.tan(math.pi / 4 + self.phi1 / 2), self.n))/ self.n
def calculate_all(self): ''' FDA Method's Approach : F`(X) ≈ [F(X + ΔX) - F(X)] / ΔX Where ΔX Is Equal To The Value Of Size Of Step. ''' if (int(func_scale.get()) == 1): ''' Since The Derivative Of exp(X) Is Equal To Itself, Both Results Will Be Extremely Irrelevant Towards Each Other. No Form Of Correlation Is Shown, Thus The Value Of Abs. Relative True Error Will Be Extremely High. ''' # Calculations. exact_value = np.exp(float(x_val_entry.get())) appr_value = (np.exp( (float(x_val_entry.get()) + float(delta_x_entry.get()))) - exact_value) / float(delta_x_entry.get()) abs_error = str( round( np.abs((exact_value - appr_value) / exact_value) * float(100.0), 5)) + " %" self.clear_all() # Insertions Where Results Are Rounded Off To At Most 5 Decimal Points. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error) elif (int(func_scale.get()) == 2): ''' Derivative Of ln(X) -> np.log(X) Is X**(-1) Which Will Be Used For Calculating Exact Values. ''' try: exact_val = 1 / (float(x_val_entry.get())**(1.0)) appr_val = (np.log( (float(x_val_entry.get()) + float(delta_x_entry.get()) )) - np.log(float(x_val_entry.get()))) / float( delta_x_entry.get()) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 3): ''' Derivative Of X**(-1) Is -1*(X**(-2)). ''' try: exact_val = -1 * (1 / (float(x_val_entry.get())**(2.0))) appr_val = (((float(x_val_entry.get()) + float(delta_x_entry.get()))**(-1.0)) - (float(x_val_entry.get())**(-1.0))) / float( delta_x_entry.get()) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 4): ''' Derivative Of 10**(X) Is ln(10) * 10**(X). ''' try: exact_val = np.log(float(10.0)) * (10**(float( x_val_entry.get()))) appr_val = (10**( (float(x_val_entry.get()) + float(delta_x_entry.get())))) - (10**(float( x_val_entry.get()))) / float(delta_x_entry.get()) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 5): ''' Derivative Of log(X)[Base = 10] Is (ln(10) * X)**(-1). ''' try: exact_val = 1 / (np.log(float(10.0)) * float(x_val_entry.get())) appr_val = ((np.log10( (float(x_val_entry.get()) + float(delta_x_entry.get()) ))) - np.log10(float(x_val_entry.get()))) / float( delta_x_entry.get()) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 6): ''' Derivative Of log(X)[Base = 2] Is (ln(2) * X)**(-1). ''' try: exact_val = 1 / (np.log(float(2.0)) * float(x_val_entry.get())) appr_val = (np.log2( (float(x_val_entry.get()) + float(delta_x_entry.get()) )) - np.log2(float(x_val_entry.get()))) / float( delta_x_entry.get()) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 7): ''' Derivative Of Sin(X) Is Cos(X). ''' try: exact_val = np.cos(math.radians(float(x_val_entry.get()))) appr_val = (np.sin( (math.radians(float(x_val_entry.get())) + math.radians(float(delta_x_entry.get())))) - np.sin(math.radians(float(x_val_entry.get()))) ) / math.radians(float(delta_x_entry.get())) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 8): ''' Derivative Of Cos(X) Is -Sin(X). ''' try: exact_val = float(-1.0) * np.sin( math.radians(float(x_val_entry.get()))) appr_val = (np.cos( (math.radians(float(x_val_entry.get())) + math.radians(float(delta_x_entry.get())))) - np.cos(math.radians(float(x_val_entry.get()))) ) / math.radians(float(delta_x_entry.get())) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 9): ''' Derivative Of Tan(X) Is Sec^2(X). ''' try: exact_val = float( sec(float(math.radians(x_val_entry.get()))))**(2.0) appr_val = (tan( math.radians(float(x_val_entry.get())) + math.radians(float(delta_x_entry.get()))) - tan(math.radians(float(x_val_entry.get()))) ) / math.radians(float(delta_x_entry.get())) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 10): ''' Derivative Of X^2 Is 2 * X. ''' try: exact_val = float(2 * float(x_val_entry.get())) appr_val = (((float(x_val_entry.get()) + float(delta_x_entry.get()))**(2.0)) - (float(x_val_entry.get())**(2.0))) / float( delta_x_entry.get()) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 11): ''' Derivative Of √X Is 1 / (2 * √X). ''' try: exact_val = float(1 / (2 * sqrt(float(x_val_entry.get())))) appr_val = (sqrt( (float(x_val_entry.get()) + float(delta_x_entry.get()) )) - sqrt(float(x_val_entry.get()))) / float( delta_x_entry.get()) abs_error_val = str( round( np.abs((exact_val - appr_val) / exact_val) * float(100.0), 5)) + " %" self.clear_all() exact_entry.insert(self.__length_of_exact_entry, str(round(exact_val, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_val, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, abs_error_val) except Exception: msb.showerror("INFO", "An Error Occured !") elif (int(func_scale.get()) == 12): msb.showinfo("'None' Specified !", "No Function Is Specified.") else: msb.showerror("Invalid Selection", "Please Try Again.")
def fun(x): z = np.tan(x) function = ((z**3) * mpmath.sec(x)**2) / ((np.exp(z) - 1)) return function
def calculate_all(self): ''' CDDA Method's Approach : F`(X) = [F(X + ΔX) - F(X - ΔX)] / [2 * ΔX] Where ΔX Is The Step Size. The Method "scipy.misc.derivative(func, x0, dx)" Follows This Procedure. ''' if (int(scale_for_func.get()) == 1): # Functions : func = lambda x: np.exp(x) derived_func = func # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = float( derivative(func=np.exp, x0=float(x_value_entry.get()), dx=float(delta_x_input_entry.get()))) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 2): # Functions : func = lambda x: np.log(x) derived_func = lambda x: 1 / x # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative(func=np.log, x0=float(x_value_entry.get()), dx=float(delta_x_input_entry.get())) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 3): # Functions : function = lambda x: 1 / x derived_func = lambda x: -1 / (x**(2.0)) # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative(func=function, x0=float(x_value_entry.get()), dx=float(delta_x_input_entry.get())) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 4): # Functions : function = lambda x: (10**x) derived_func = lambda x: np.log(10) * (10**(x)) # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative(func=function, x0=float(x_value_entry.get()), dx=float(delta_x_input_entry.get())) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 5): # Functions : function = lambda x: np.log10(x) derived_func = lambda x: 1 / (np.log(10) * x) # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative(func=function, x0=float(x_value_entry.get()), dx=float(delta_x_input_entry.get())) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 6): # Functions : function = lambda x: np.log2(x) derived_func = lambda x: 1 / (np.log(2) * x) # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative(func=function, x0=float(x_value_entry.get()), dx=float(delta_x_input_entry.get())) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 7): # Functions : function = lambda x: math.sin(math.radians(x)) derived_func = lambda x: math.cos(math.radians(x)) # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative( func=np.sin, x0=math.radians(float(x_value_entry.get())), dx=math.radians(float(delta_x_input_entry.get()))) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 8): # Functions : function = lambda x: math.cos(math.radians(x)) derived_func = lambda x: -1 * (math.sin(math.radians(x))) # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative( func=np.cos, x0=math.radians(float(x_value_entry.get())), dx=math.radians(float(delta_x_input_entry.get()))) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 9): # Functions : function = lambda x: np.tan(math.radians(x)) derived_func = lambda x: ((mpmath.sec(mpmath.radians(x)))**(2)) # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative( func=np.tan, x0=math.radians(float(x_value_entry.get())), dx=math.radians(float(delta_x_input_entry.get()))) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 10): # Functions : function = lambda x: x**(2.0) derived_func = lambda x: 2 * x # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative(func=function, x0=float(x_value_entry.get()), dx=float(delta_x_input_entry.get())) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 11): # Functions : function = lambda x: math.sqrt(x) derived_func = lambda x: (1 / (2 * function(x))) # Calculations : exact_value = derived_func(float(x_value_entry.get())) appr_value = derivative(func=function, x0=float(x_value_entry.get()), dx=float(delta_x_input_entry.get())) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions : exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 12): msb.showinfo("'None' Selected !", "Please Select Another Function !") else: msb.showerror("Error", "Please Try Again !")
def f(x): z=np.tan(x) der=(math.exp(z))-1 f=((z**3)*((math.sec(x))**2))/(der) return f
def run(self, context): return mpmath.sec(self.body.run(context))
def calculate_all(self): ''' BDA Method's Approach : F`(X) ≈ [F(X) - F(X - ΔX)] / ΔX Where ΔX Is Equal To Value Of Step Size. ''' if (int(scale_for_func.get()) == 1): # Functions : func = lambda x: np.exp(x) derived_func = func # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 2): # Functions : func = lambda x: np.log(x) derived_func = lambda x: 1 / x # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 3): # Functions : func = lambda x: 1 / x derived_func = lambda x: -1 / (x**(2.0)) # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 4): # Functions : func = lambda x: 10**x derived_func = lambda x: np.log(10) * (10**(x)) # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 5): # Functions : func = lambda x: np.log10(x) derived_func = lambda x: 1 / (np.log(10) * x) # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 6): # Functions : func = lambda x: np.log2(x) derived_func = lambda x: 1 / (np.log(2) * x) # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 7): # Functions : func = lambda x: math.sin(math.radians(x)) derived_func = lambda x: math.cos(math.radians(x)) # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 8): # Functions : func = lambda x: math.cos(math.radians(x)) derived_func = lambda x: -1 * (math.sin(math.radians(x))) # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 9): # Functions : func = lambda x: mpmath.tan(mpmath.radians(x)) derived_func = lambda x: ((mpmath.sec(mpmath.radians(x)))**(2)) # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 10): # Functions : func = lambda x: x**(2.0) derived_func = lambda x: 2 * x # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 11): # Functions : func = lambda x: math.sqrt(x) derived_func = lambda x: (1 / (2 * func(x))) # Calculations. exact_value = derived_func(float(x_value_entry.get())) appr_value = (func(float(x_value_entry.get())) - func( (float(x_value_entry.get()) - float(delta_x_input_entry.get())))) / float( delta_x_input_entry.get()) abs_error_value = (np.abs( ((exact_value - appr_value) / exact_value))) * float(100.0) self.clear_all() # Insertions. exact_entry.insert(self.__length_of_exact_entry, str(round(exact_value, 5))) appr_entry.insert(self.__length_of_appr_entry, str(round(appr_value, 5))) abs_error_entry.insert(self.__length_of_abserror_entry, str(round(abs_error_value, 5)) + " %") elif (int(scale_for_func.get()) == 12): msb.showinfo("'None' Selected !", "Please Select Another Function !") else: msb.showerror("Error", "Please Try Again !")
async def find_sec(event): input_str = float(event.pattern_match.group(1)) output = mpmath.sec(input_str) await event.edit(f"**Value of Sec {input_str}\n==>>**`{output}`")
def f(x): z = np.tan(x) f = ((z**3) * math.sec(x)**2) / ((e**(z) - 1)) return f
def tile_from_coord(lng, lat, zoom): n = 2**zoom xtile = ((lng + 180.0) / 360.0) * n ytile = (1.0 - (math.log(math.tan(lat*math.pi/180.0) + mpmath.sec(lat*math.pi/180.0)) / math.pi)) / 2.0 * n return int(xtile), int(ytile), xtile-int(xtile), ytile-int(ytile)
def lat_to_tiley(lat, zoom): lat1 = lat * mpmath.pi / 180.0 result = int( (1.0 - math.log(mpmath.tan(lat1) + mpmath.sec(lat1)) / mpmath.pi) / 2.0 * (2.0**zoom)) return result