else: for j in range(L): if A[j] > mi and A[j] <= mx: H[2 * i] = H[2 * i] + 1 H[2 * i + 1] = H[2 * i + 1] + 1 H[2 * i] = H[2 * i] / L H[2 * i + 1] = H[2 * i + 1] / L plt.plot(X, H) plt.ylim(0, 1) plt.show() A = np.zeros(100000) for m in range(100000): A[m] = intr.exponential(2) hist(A, 100) #The histogram looks very similar to the expected probability density function. [w, Sw] = intr.monte_carlo_3d(intr.density, [-0.5, -0.5, -1], [1, 1, 1], intr.sphere, 100000) [x, Sx] = intr.monte_carlo_3d(intr.xmoment, [-0.5, -0.5, -1], [1, 1, 1], intr.sphere, 100000) [y, Sy] = intr.monte_carlo_3d(intr.ymoment, [-0.5, -0.5, -1], [1, 1, 1], intr.sphere, 100000) [z, Sz] = intr.monte_carlo_3d(intr.zmoment, [-0.5, -0.5, -1], [1, 1, 1], intr.sphere, 100000) print(x / w, y / w, z / w)
# plt.plot(x,y1,x,y2) # [x,w] = intr.gauss_leg(0,1,3) ##print(x,w) # print(intr.trap(intr.quar,0,1,100)) # print(intr.gauss_quad(intr.quar,x,w)) # rng.init(pow(2,31),65539,0,1) # N = 10000 # rand1 = np.zeros(N) # rand2 = np.zeros(N) # rand3 = np.zeros(N) # for i in range(N): # rand1[i]=rng.lcg() # rand2[i]=rng.lcg() # rand3[i]=rng.lcg() # ##plt.scatter(rand1,rand2) # fig = plt.figure() # ax = fig.add_subplot(111,projection="3d") # ax.scatter(rand1,rand2,rand3) # # plt.show() [w, Sw] = intr.monte_carlo_3d(intr.density, [0, -4, -1], [4, 4, 1], intr.torus, 100000) [x, Sx] = intr.monte_carlo_3d(intr.xmoment, [0, -4, -1], [4, 4, 1], intr.torus, 100000) [y, Sy] = intr.monte_carlo_3d(intr.ymoment, [0, -4, -1], [4, 4, 1], intr.torus, 100000) [z, Sz] = intr.monte_carlo_3d(intr.zmoment, [0, -4, -1], [4, 4, 1], intr.torus, 100000) print(x / w, y / w, z / w)
# break # elif check >= max_A: # index = N-1 #sum_check = 0 ## finds out which bin the "check" value lies within and spits out the index of that bin location #for h in range(index+1): # sum_check = sum_check+normalized[h]*dx ##sums up the area up until the "check" value #print("estimated") #print(1-sum_check) # #plt.show() ############################# #Assignment 6 Problem 2 [w,Sw] = intr.monte_carlo_3d(intr.density,[-.5,-.5,-1],[1,1,1],intr.sphere,100000) [x,Sx] = intr.monte_carlo_3d(intr.xmoment,[-.5,-.5,-1],[1,1,1],intr.sphere,100000) [y,Sy] = intr.monte_carlo_3d(intr.ymoment,[-.5,-.5,-1],[1,1,1],intr.sphere,100000) [z,Sz] = intr.monte_carlo_3d(intr.zmoment,[-.5,-.5,-1],[1,1,1],intr.sphere,100000) print("CG of sphere with box (CGx,CGy,CGz) print(x/w,y/w,z/w) #print(intr.trap(intr.cub, 0, 1, 100)) ########################## #a = -1 #b = 1 #N = 10000 #h = (b-a) / (N-1) #x = np.zeros(N)
#print(intr.trap(intr.quar,0,1,100)) #print(intr.gauss_quad(intr.quar,x,w)) #rng.init(pow(2,31),65539,0,1) #N = 10000 #rand1 = np.zeros(N) #rand2 = np.zeros(N) #rand3 = np.zeros(N) #for i in range(N): # rand1[i]=rng.lcg() # rand2[i]=rng.lcg() # rand3[i]=rng.lcg() # ##plt.scatter(rand1,rand2) #fig = plt.figure() #ax = fig.add_subplot(111,projection="3d") #ax.scatter(rand1,rand2,rand3) # #plt.show() [w, Sw] = intr.monte_carlo_3d(intr.density, [0, -4, -1], [4, 4, 1], intr.torus, 100000) [x, Sx] = intr.monte_carlo_3d(intr.xmoment, [0, -4, -1], [4, 4, 1], intr.torus, 100000) [y, Sy] = intr.monte_carlo_3d(intr.ymoment, [0, -4, -1], [4, 4, 1], intr.torus, 100000) [z, Sz] = intr.monte_carlo_3d(intr.zmoment, [0, -4, -1], [4, 4, 1], intr.torus, 100000) print(x / w, y / w, z / w)