def e_LB(v, tau): symp_int[0] = v[0] symp_int[1] = v[1] symp_int[2] = v[2] - tau * (v[0] + 2 * v[0] * v[1]) symp_int[3] = v[3] - tau * (v[1] + p(v[0], 2) - p(v[1], 2)) symp_int[4] = v[4] symp_int[5] = v[5] symp_int[6] = v[6] - tau * (v[4] * (1 + 2 * v[1]) + 2 * v[0] * v[5]) symp_int[7] = v[7] + tau * (-2 * v[0] * v[4] + v[5] * (-1 + 2 * v[1])) symp_int[8] = v[8] symp_int[9] = v[9] symp_int[10] = v[10] - tau * (v[8] * (1 + 2 * v[1]) + 2 * v[0] * v[9]) symp_int[11] = v[11] + tau * (-2 * v[0] * v[8] + v[9] * (-1 + 2 * v[1])) symp_int[12] = v[12] symp_int[13] = v[13] symp_int[14] = v[14] - tau * (v[12] * (1 + 2 * v[1]) + 2 * v[0] * v[13]) symp_int[15] = v[15] + tau * (-2 * v[0] * v[12] + v[13] * (-1 + 2 * v[1])) symp_int[16] = v[16] symp_int[17] = v[17] symp_int[18] = v[18] - tau * (v[16] * (1 + 2 * v[1]) + 2 * v[0] * v[17]) symp_int[19] = v[19] + tau * (-2 * v[0] * v[16] + v[17] * (-1 + 2 * v[1])) return symp_int
def func(v): global rk_f rk_f[0] = v[2] #corresponds to t-deriv. of x rk_f[1] = v[3] #corresponds to t-deriv. of y rk_f[2] = -(v[0] + 2 * v[0] * v[1]) #corresponds to t-deriv. of p_x rk_f[3] = p(v[1], 2) - v[1] - p(v[0], 2) #corresponds to t-deriv. of p_y return rk_f
def e_LB(v, tau): symp_int[0] = v[0] symp_int[1] = v[1] symp_int[2] = v[2] - tau * (v[0] + 2 * v[0] * v[1]) symp_int[3] = v[3] - tau * (v[1] + p(v[0], 2) - p(v[1], 2)) return symp_int
def h(a, b): u, v = p(a) x, y = p(b) h, j = u * x, int(v + y) return q(h, j)
def run(trials=4, outs=2): sum = 0.0 for i in range(outs + 1): iteration = p(-1, i) * p( (1.0) * (outs - i) / outs, trials) * f(outs) / f(i) / f(outs - i) sum += iteration print("probability:", sum)
def e_LB(v, tau): symp_int[0] = v[0] symp_int[1] = v[1] symp_int[2] = v[2] - tau*(v[0] + 2*v[0]*v[1]) symp_int[3] = v[3] - tau*(v[1] + p(v[0], 2) - p(v[1], 2)) symp_int[4] = v[4] symp_int[5] = v[5] symp_int[6] = v[6] - tau*(v[4]*(1 + 2*v[1]) + 2*v[0]*v[5]) symp_int[7] = v[7] + tau*(-2*v[0]*v[4] + v[5]*(-1 + 2*v[1])) return symp_int
def check_pythagorean_triple(nums): nums = nums.split(' ') nums = [int(num) for num in nums] if p(nums[0], 2) + p(nums[1], 2) == p(nums[2], 2): return True if p(nums[1], 2) + p(nums[2], 2) == p(nums[0], 2): return True if p(nums[2], 2) + p(nums[0], 2) == p(nums[1], 2): return True return False
def sumoflf(k): g = [] from math import pow as p for i in range(len(k)): s = 0 s = s + int(k[i] % 10) + int(k[i] / p(10, len(str(k[i])) - 1)) g.append(s) return g
def reverse(a): s = 0 l = len(str(a)) from math import pow as p while (a / 10) != 0: r = a % 10 s = s + r * p(10, l - 1) a = int(a / 10) l = l - 1 print(int(s))
import time V = np.zeros(4) V_new = np.zeros(4) K = 0.971635 tp = 2*np.pi steps = 1e3 m = 1 n = -1 linIC_density = 60 initials = int(p(linIC_density, 2)) initConds = np.zeros([initials, 2]) for j in range(0, initials): initConds[j, 0] = (j/linIC_density)%1.0 initConds[j, 1] = np.floor(j/linIC_density)/linIC_density def standMap(v): V_new[1] = v[1] + K*np.sin(tp*v[0])/tp V_new[0] = v[0] + V_new[1] V_new[3] = v[2]*K*np.cos(tp*v[0])/tp + v[3] V_new[2] = V_new[3] + v[2] return V_new
from __future__ import division from math import sqrt from math import exp from math import pow as p import numpy as np import matplotlib.pyplot as plt H = 1 / 8 numPoints = 10000 y = np.linspace(-0.4396, 0.6735, numPoints) ## py = np.zeros(numPoints) for i in range(0, numPoints): py[i] = sqrt(2 * (H + p(y[i], 3) / 3) - p(y[i], 2)) ## initConds = [[0., 0.]] count = 0 condArray = [0] #f= open("initCondsH=0125.txt","r") f = open("initCondsContour.txt", "r") if f.mode == 'r': contents = f.readlines() for line in contents: count += 1 condArray = np.append(condArray, float(line)) for s in range(0, int(count / 2)): initConds = np.append(initConds,
from math import sqrt as s, pow as p, ceil as c, floor, pi, e x = s(26) print("Floor value " + str(floor(x))) #floor is the lower value while rounding figure print("Ceil value " + str(c(x))) #ceil is the upper value while rounding figure print("Power of " + str(p(2, 31))) print("Pi value " + str(pi)) print("e value " + str(e)) import math as m x = m.sqrt(26) print("Floor value " + str(m.floor(x))) #floor is the lower value while rounding figure print("Ceil value " + str(m.ceil(x))) #ceil is the upper value while rounding figure print("Power of " + str(m.pow(2, 31))) print("Pi value " + str(m.pi)) print("e value " + str(m.e))
V_new[7] = v[7] + v[6] * c3 + c13 * (v[6] - v[4]) V_new[6] = v[6] + V_new[7] return V_new i = 1 #np.random.seed(0) dev = np.array([ np.random.uniform(low=-1.0, high=1.0, size=None), np.random.uniform(low=-1.0, high=1.0, size=None), np.random.uniform(low=-1.0, high=1.0, size=None), np.random.uniform(low=-1.0, high=1.0, size=None) ]) mag = sqrt(p(dev[0], 2) + p(dev[1], 2) + p(dev[2], 2) + p(dev[3], 2)) dev = dev / mag mag = sqrt(p(dev[0], 2) + p(dev[1], 2) + p(dev[2], 2) + p(dev[3], 2)) print 'Regular orbit ICs: ', initConds print 'Regular orbit deviation vector: ', dev print 'Magnitude: ', mag print V = np.concatenate((initConds, dev)) renorm = 10 k = 0 X1 = np.zeros(int(steps / renorm)) X1[0] = 1
def evolveDev(v, d): evolve[0] = d[0] + dt * d[2] evolve[1] = d[1] + dt * d[3] evolve[2] = d[2] + dt * (-d[0] * (1 + 2 * v[1]) - 2 * v[0] * d[1]) evolve[3] = d[3] + dt * (-2 * v[0] * d[0] + d[1] * (2 * v[1] - 1)) return evolve H0 = 1 / 8 H = H0 xi = 0.0 yi = 0.1 #Regular orbit pyi = 0.0 pxi = sqrt(2 * (H0 + p(yi, 3) / 3 - p(xi, 2) * yi) - p(xi, 2) - p(yi, 2) - p(pyi, 2)) initConds = np.array([xi, yi, pxi, pyi]) i = 1 j = 0 #np.random.seed(0) dev = np.array([ np.random.uniform(low=-1.0, high=1.0, size=None), np.random.uniform(low=-1.0, high=1.0, size=None), np.random.uniform(low=-1.0, high=1.0, size=None), np.random.uniform(low=-1.0, high=1.0, size=None) ]) mag = sqrt(p(dev[0], 2) + p(dev[1], 2) + p(dev[2], 2) + p(dev[3], 2))
def correlation_rule_sum(m): return int(sum(combination(m, k) * (p(2, k) - 2) for k in range(2, m + 1)))
interpVec[1] = vn[1] + T * (f[1]) / (f[0]) interpVec[2] = vn[2] + T * (f[2]) / (f[0]) interpVec[3] = vn[3] + T * (f[3]) / (f[0]) interpVec[4] = tn + T / f[0] return interpVec xi = 0.0 #yi = 0.1 #Regular orbit #yi = -0.1 #Chaotic orbit #pyi = 0.44 yi = 0.44 #Sticky pyi = 0.13 pxi = sqrt(2 * (H0 + p(yi, 3) / 3 - p(xi, 2) * yi) - p(xi, 2) - p(yi, 2) - p(pyi, 2)) initConds = np.array([xi, yi, pxi, pyi]) i = 1 a1 = 0.0711334264982231177779387300061549964174 a2 = 0.241153427956640098736487795326289649618 a3 = 0.521411761772814789212136078067994229991 a4 = -0.333698616227678005726562603400438876027 b1 = 0.183083687472197221961703757166430291072 b2 = 0.310782859898574869507522291054262796375 b3 = -0.0265646185119588006972121379164987592663 b4 = 0.0653961422823734184559721793911134363710
def lug_calc(L, H, t, d, D_p, a_1, a_2, beta, phi, t_w, W, sigma_t, sigma_s, sigma_p, sigma_b, tau_allowable, x_1, x_2, report_id, component_react_id): '''Perform all calculations for lifting lug as per calcgen report 18-001-Calculations.pdf Arguments: L {float} -- length in inches H {float} -- height in inches t {float} -- thickness in inches d {float} -- hole diameter in inches D_p {float} -- pin diameter in inches a_1 {float} -- load eccentricity in inches a_2 {float} -- distance from load to shell or pad in inches beta {float} -- load angle normal to vessel in degree phi {float} -- load angle from vertical in degree t_w {float} -- weld size in inches W {float} -- weight of the vessel sigma_t {float} -- allowable stress, Tensile in psi sigma_s {float} -- allowable stress, Shear in psi sigma_p {float} -- allowable stress, Bearing in psi sigma_b {float} -- allowable stress, Bending in psi tau_allowable {float} -- allowable stress, weld shear in psi x_1 {float} -- distance between this lug and the center of gravity x_2 {float} -- distance between second lift lug and the center of gravity ''' # calculate lift forces # force on vessel at lug, F_r F_r = (W / cos(phi * pi / 180)) * (1 - x_1 / (x_1 + x_2)) # calculate lug pin diameter -shear stress # lug pin diamter, d_reqd d_reqd = p(2 * F_r / (pi * sigma_s), 0.5) diameter_ratio = d_reqd / D_p # error_check(diameter_ratio, d_reqd, 'Lug pin diameter is not acceptable') # calculate shear stress sigma_sd_calc = F_r / (2 * (0.25 * pi * p(D_p, 2))) sigma_sd_ratio = sigma_sd_calc / sigma_s # error_check(sigma_sd_ratio, sigma_sd_calc, # 'shear stress is not acceptable') # calculate lug thickness - tensile stress # required lug thickness, t_reqd t_reqd_tensile = F_r / ((L - d) * sigma_t) # thickness_ratio = t_reqd / t t_max = t_reqd_tensile # error_check(thickness_ratio, t_reqd, # 'thickness is not acceptable due to tensile stress') # calculate tensile stress sigma_t_calc = F_r / ((L - d) * t) sigma_t_ratio = sigma_t_calc / sigma_t # error_check(sigma_t_ratio, sigma_t_calc, # 'tensile stress is not acceptable') # calculate lug thickness - bearing stress # required lug thickness t_reqd_bearing = F_r / (D_p * sigma_p) if t_reqd_bearing > t_max: t_max = t_reqd_bearing # thickness_ratio = t_reqd / t # error_check(thickness_ratio, t_reqd, # 'thickness is not acceptable due to bearing stress') # calculate bearing stress A_bearing = (D_p * (t)) sigma_b_calc = F_r / A_bearing sigma_b_ratio = sigma_b_calc / sigma_b # error_check(sigma_b_ratio, sigma_b_calc, # 'bearing stress is not acceptable') # calculate shear stress length phi_shear = 55 * D_p / d # print('***********')] # print(H, a2, d, Dp, ) L_shear = (H - a_2 - 0.5 * d) + 0.5 * D_p * (1 - cos(phi_shear * pi / 180)) # calculate lug thickness - shear stress # required lug thickness t_reqd_shear = (F_r / sigma_s) / (2 * L_shear) if t_reqd_shear > t_max: t_max = t_reqd_shear thickness_ratio = t_max / t # thickness_ratio = t_reqd/t # error_check(thickness_ratio, t_reqd, # 'thickness is not acceptable due to shear stress') A_shear = 2 * t * L_shear tau = F_r / A_shear sigma_s_ratio = tau / sigma_s # error_check(sigma_s_ratio, tau, 'shear stress is not acceptable') # calculate lug plate stress # dont understand the formula M_bend and Z_bend # how to get those quantities # calculate weld stress A_weld = 2 * 0.707 * t_w * (L + t) alpha = 0.0 tau_t = F_r * cos(alpha * pi / 180) / A_weld tau_s = F_r * sin(alpha * pi / 180) / A_weld M = 3.0 # how to calculate M Hght = 3.0 # how to calculate hght c = F_r * sin(alpha * pi / 180) * Hght - F_r * cos(alpha * pi / 180) * a_1 h = 1.0 # how to calculate h what is h? l = 0.707 * h * L * (3 * t + L) tau_b = M * abs(c) / l tau_ratio = p(p(tau_t + tau_b, 2) + p(tau_s, 2), 1 / 2) / tau_allowable return_dict = { 'lift_force': F_r, 'lug_pin_diameter': { 'req_value': d_reqd, 'check': error_check(diameter_ratio) }, 'lug_thickness': { 'req_value': t_max, 'check': error_check(thickness_ratio) }, 'shear_stress_for_diameter': { 'req_value': sigma_sd_calc, 'check': error_check(sigma_sd_ratio) }, 'tensile_stress': { 'req_value': sigma_t_calc, 'check': error_check(sigma_t_ratio) }, 'bearing_stress': { 'req_value': sigma_b_calc, 'check': error_check(sigma_b_ratio) }, 'shear_stress_thickness': { 'req_value': tau, 'check': error_check(sigma_s_ratio) }, 'phi': phi, 'length_shear': L_shear, 'weld_area': A_weld, 'lift_shear_stress': tau_s, 'lift_tensile_stress': tau_t, 'lift_bending_stress': tau_b, 'tau_ratio': tau_ratio, 'phi_shear': phi_shear } try: report = Report.objects.get(id=report_id) except: raise newError( {"database": ["Report cannot be found Please Create the report"]}) try: component = Component.objects.filter( report__id=report_id, react_component_id=component_react_id)[0] except: raise newError({ "database": ["Component cannot be found Please Create the component"] }) lug_state = LiftingLugState.objects.filter( report__id=report_id, component__id=component.id ).update( W=W, phi=phi, x_1=x_1, x_2=x_2, F_r=F_r, d_reqd=d_reqd, diameter_ratio=diameter_ratio, D_p=D_p, sigma_sd_calc=sigma_sd_calc, sigma_sd_ratio=sigma_sd_ratio, t_reqd_tensile=t_reqd_tensile, L=L, d=d, sigma_t=sigma_t, sigma_b=sigma_b, sigma_t_calc=sigma_t_calc, sigma_t_ratio=sigma_t_ratio, t=t, t_reqd_bearing=t_reqd_bearing, A_bearing=A_bearing, sigma_b_calc=sigma_b_calc, sigma_b_ratio=sigma_b_ratio, phi_shear=phi_shear, L_shear=L_shear, H=H, a_2=a_2, t_reqd_shear=t_reqd_shear, t_max=t_max, thickness_ratio=thickness_ratio, A_shear=A_shear, tau=tau, sigma_s=sigma_s, sigma_s_ratio=sigma_s_ratio, A_weld=A_weld, t_w=t_w, alpha=alpha, tau_t=tau_t, tau_s=tau_s, M=M, Hght=Hght, c=c, h=h, l=l, tau_b=tau_b, tau_allowable=tau_allowable, tau_ratio=tau_ratio, lug_pin_check=return_dict['lug_pin_diameter']['check'], lug_thickness_check=return_dict['lug_thickness']['check'], shear_thickness_check=return_dict['shear_stress_thickness']['check'], shear_diameter_check=return_dict['shear_stress_for_diameter']['check'], tensile_check=return_dict['tensile_stress']['check'], bearing_check=return_dict['bearing_stress']['check']) if not lug_state: calc_steps = LiftingLugState( report=Report.objects.get(id=report_id), component=component, # provide the component object here W=W, phi=phi, x_1=x_1, x_2=x_2, F_r=F_r, d_reqd=d_reqd, diameter_ratio=diameter_ratio, D_p=D_p, sigma_sd_calc=sigma_sd_calc, sigma_sd_ratio=sigma_sd_ratio, t_reqd_tensile=t_reqd_tensile, L=L, d=d, sigma_t=sigma_t, sigma_b=sigma_b, sigma_t_calc=sigma_t_calc, sigma_t_ratio=sigma_t_ratio, t=t, t_reqd_bearing=t_reqd_bearing, A_bearing=A_bearing, sigma_b_calc=sigma_b_calc, sigma_b_ratio=sigma_b_ratio, phi_shear=phi_shear, L_shear=L_shear, H=H, a_2=a_2, t_reqd_shear=t_reqd_shear, t_max=t_max, thickness_ratio=thickness_ratio, A_shear=A_shear, tau=tau, sigma_s=sigma_s, sigma_s_ratio=sigma_s_ratio, A_weld=A_weld, t_w=t_w, alpha=alpha, tau_t=tau_t, tau_s=tau_s, M=M, Hght=Hght, c=c, h=h, l=l, tau_b=tau_b, tau_allowable=tau_allowable, tau_ratio=tau_ratio, lug_pin_check=return_dict['lug_pin_diameter']['check'], lug_thickness_check=return_dict['lug_thickness']['check'], shear_thickness_check=return_dict['shear_stress_thickness'] ['check'], shear_diameter_check=return_dict['shear_stress_for_diameter'] ['check'], tensile_check=return_dict['tensile_stress']['check'], bearing_check=return_dict['bearing_stress']['check']) calc_steps.save() return return_dict
""" This problem was asked by Google. The area of a circle is defined as πr^2. Estimate π to 3 decimal places using a Monte Carlo method. Hint: The basic equation of a circle is x^2 + y^2 = r^2. """ from random import random as r from math import pow as p print(sum([4 if p(r(), 2) + p(r(), 2) < 1 else 0 for x in range(1e7)])/1e7)
import time V = np.zeros(4) V_new = np.zeros(4) K = 0.971635 tp = 2 * np.pi steps = 1e4 m = 1 n = -1 linIC_density = 60 initials = int(p(linIC_density, 2)) initConds = np.zeros([initials, 2]) for j in range(0, initials): initConds[j, 0] = (j / linIC_density) % 1.0 initConds[j, 1] = np.floor(j / linIC_density) / linIC_density def standMap(v): V_new[1] = v[1] + K * np.sin(tp * v[0]) / tp V_new[0] = v[0] + V_new[1] V_new[3] = v[2] * K * np.cos(tp * v[0]) / tp + v[3] V_new[2] = V_new[3] + v[2]
'''#import math #print(math.sqrt(49)) import math as m print(m.pow(2,3)) print(m.ceil(12.001)) print(m.floor(12.99991)) print(m.log(m.e)) print(m.exp(2.5)) print(m.pi) print(m.tan(45*(m.pi/180))) print(m.sin(30*(m.pi/180))) print(m.cos(60*(m.pi/180))) print(m.atan(1)/(m.pi/180)) ''' from math import pow as p print(p(2, 3))
def max_matching_count(seq): a, c, g, u = seq.count('A'), \ seq.count('C'), \ seq.count('G'), \ seq.count('U') return (p(a, u) if a > u else p(u, a)) * (p(c, g) if c > g else p(g, c))
import numpy as np import matplotlib.pyplot as plt H0 = 1 / 8 H = 0 length = 60 #Linear density of points y = np.linspace(-0.4397, 0.6736, length) py = np.linspace(-0.5, 0.5, length) initConds = [[0., 0.]] for i in range(0, length): #y for j in range(0, length): #py H = 0.5 * (p(py[j], 2) + p(y[i], 2)) - p(y[i], 3) / 3 if H <= H0: initConds = np.append(initConds, [[y[i], py[j]]], axis=0) initConds = np.delete(initConds, 0, 0) number = np.size(initConds, 0) print 'ICs: ', number #f= open("initCondsH=0125.txt","w+") f = open("initCondsContour.txt", "w+") for k in range(0, number): for l in range(0, 2): f.write(str(initConds[k, l])) f.write("\n")
V_new[16] = v[16] + V_new[17] V_new[19] = v[19] + v[18]*c3 + c13*(v[18] - v[16]) V_new[18] = v[18] + V_new[19] return V_new i = 1 #np.random.seed(0) rndm = np.array([np.random.uniform(low = -1.0, high = 1.0, size = None), np.random.uniform(low = -1.0, high = 1.0, size = None), np.random.uniform(low = -1.0, high = 1.0, size = None), np.random.uniform(low = -1.0, high = 1.0, size = None)]) dev1 = np.array([1.0, 0.0, 0.0, 0.0]) + rndm dev2 = np.array([0.0, 1.0, 0.0, 0.0]) + rndm dev3 = np.array([0.0, 0.0, 1.0, 0.0]) + rndm dev4 = np.array([0.0, 0.0, 0.0, 1.0]) + rndm mag1 = sqrt(p(dev1[0], 2) + p(dev1[1], 2) + p(dev1[2], 2) + p(dev1[3], 2)) mag2 = sqrt(p(dev2[0], 2) + p(dev2[1], 2) + p(dev2[2], 2) + p(dev2[3], 2)) mag3 = sqrt(p(dev3[0], 2) + p(dev3[1], 2) + p(dev3[2], 2) + p(dev3[3], 2)) mag4 = sqrt(p(dev4[0], 2) + p(dev4[1], 2) + p(dev4[2], 2) + p(dev4[3], 2)) dev1 = dev1/mag1 dev2 = dev2/mag2 dev3 = dev3/mag3 dev4 = dev4/mag4 print 'ICs: ', initConds print 'Deviation vector 1: ', dev1 print 'Deviation vector 2: ', dev2 print 'Deviation vector 3: ', dev3 print 'Deviation vector 4: ', dev4 print
symp_int[1] = v[1] symp_int[2] = v[2] - tau * (v[0] + 2 * v[0] * v[1]) symp_int[3] = v[3] - tau * (v[1] + p(v[0], 2) - p(v[1], 2)) symp_int[4] = v[4] symp_int[5] = v[5] symp_int[6] = v[6] - tau * (v[4] * (1 + 2 * v[1]) + 2 * v[0] * v[5]) symp_int[7] = v[7] + tau * (-2 * v[0] * v[4] + v[5] * (-1 + 2 * v[1])) return symp_int xi = 0.0 yi = 0.1 #Regular orbit pyi = 0.0 pxi = sqrt(2 * (H0 + p(yi, 3) / 3 - p(xi, 2) * yi) - p(xi, 2) - p(yi, 2) - p(pyi, 2)) initConds = np.array([xi, yi, pxi, pyi]) i = 1 j = 1 a1 = 0.0711334264982231177779387300061549964174 a2 = 0.241153427956640098736487795326289649618 a3 = 0.521411761772814789212136078067994229991 a4 = -0.333698616227678005726562603400438876027 b1 = 0.183083687472197221961703757166430291072 b2 = 0.310782859898574869507522291054262796375 b3 = -0.0265646185119588006972121379164987592663 b4 = 0.0653961422823734184559721793911134363710
from math import pow as p x = int(input("Enter the value for x: ")) answer = 3 * p(x, 5) + 2 * p(x, 4) - 5 * p(x, 3) - p(x, 2) + 7 * x - 6 print(f"The answer is {answer:.0f}")
from math import factorial as f from math import pow as p from functools import reduce def combination(n, r): return int(f(n) / (f(r) * f(n - r))) def correlation_rule_sum(m): return int(sum(combination(m, k) * (p(2, k) - 2) for k in range(2, m + 1))) col_sum = correlation_rule_sum(5) s = col_sum * 200 ans_s = s / (1.6 * p(10, 6)) ans_m = ans_s / 60 ans_h = ans_m / 60 print(col_sum) print(s) print(str(ans_s) + " (sec)") print(str(ans_m) + " (minute)") print(str(ans_h) + " (hour)") # # result = reduce(lambda a, x: a * combination(x, 10), range(80, 0, -10), 1) # result = 1 # for i in range(80, 0, -10): # result *= combination(i, 10) # print(result / 1) # print(result / 10000000) # print(result / 10000000 / (60 * 60 * 24 * 365))
import math #math library in python to do basic math from math import pow from math import pow as p #as lets you import variable in a different name #import django-admin -- third party module import power # ** = math.pow(x,y) print (math.pow(2,3)) # output 8.0, is a float print (math.ceil(5.4)) # output 6, next biggest integer, (rounds) print(power.power(3,4)) #output 81 ex. of imported module print(pow(2,3)) # output 8.0 print(p(2,3)) # output 8.0 # itertools, collections, cmath, math """ Functions - blocks of code that do stuff sectioned, scoped, takes input, may or may not return values ex. print, input, pow, int, str, format, center, ljust, rjust... def * ** """ #Function Examples: print() def example(): #function definition print("Hello, World!") # a subroutine because it does not really return anything
valsX = np.zeros(initials) valsY = np.array([initConds[1]]) #initConds[:, 0] valsPy = np.array([initConds[3]]) #initConds[:, 1] valsPx = np.zeros(initials) xi = 0.0 yi = 0.0 pxi = 0.0 pyi = 0.0 for k in range(0, initials): xi = valsX[k] yi = valsY[k] pyi = valsPy[k] #print '', xi, ', ', yi, ', ', pyi pxi = sqrt(2 * (H0 + p(yi, 3) / 3 - p(xi, 2) * yi) - p(xi, 2) - p(yi, 2) - p(pyi, 2)) valsPx[k] = pxi #print(pxi) initConds[2] = pxi #print(initConds) plt.scatter(valsY, valsPy, s=1, c='black') i = 1 j = 0 a1 = 0.0711334264982231177779387300061549964174 a2 = 0.241153427956640098736487795326289649618 a3 = 0.521411761772814789212136078067994229991
from math import pow as p binaryNumber = input("\nEnter a binary number : ") #CONVERTING BIN TO OCT binaryNumber = int(binaryNumber) binary = binaryNumber octalNumber = 0 decimalNumber = 0 i = 0 while binaryNumber != 0: decimalNumber += (binaryNumber % 10) * int(p(2, i)) i += 1 binaryNumber //= 10 i = 1 while (decimalNumber != 0): octalNumber += (decimalNumber % 8) * i decimalNumber //= 8 i *= 10 print("\n\n\t%d in binary is %d in octal" % (binary, octalNumber))
#!/usr/bin/env python3 from random import random as r from math import pow as p from sys import argv # Use argparse to take command line options and generate help text import argparse parser = argparse.ArgumentParser() parser.add_argument("number", help="number of random points (int)", type=int) args = parser.parse_args() # Grab number of attempts from command line attempts = args.number inside = 0 tries = 0 ratio = 0. # Try the specified number of random points while (tries < attempts): tries += 1 if (p(r(), 2) + p(r(), 2) < 1): inside += 1 # Compute and print a final ratio ratio = 4. * (inside / (tries)) print("Final pi estimate from", attempts, "attempts =", ratio)
V_new[7] = v[7] + v[6] * c3 + c13 * (v[6] - v[4]) V_new[6] = v[6] + V_new[7] return V_new i = 1 #np.random.seed(0) dev = np.array([ np.random.uniform(low=-1.0, high=1.0, size=None), np.random.uniform(low=-1.0, high=1.0, size=None), np.random.uniform(low=-1.0, high=1.0, size=None), np.random.uniform(low=-1.0, high=1.0, size=None) ]) mag = sqrt(p(dev[0], 2) + p(dev[1], 2) + p(dev[2], 2) + p(dev[3], 2)) dev = dev / mag mag = sqrt(p(dev[0], 2) + p(dev[1], 2) + p(dev[2], 2) + p(dev[3], 2)) print 'Regular orbit ICs: ', initConds print 'Regular orbit deviation vector: ', dev print 'Magnitude: ', mag print V = np.concatenate((initConds, dev)) renorm = 10 k = 0 Y = np.zeros(int(steps / renorm)) Y_ave = np.zeros(int(steps / renorm))