import matplotlib matplotlib.use('Agg') import functions21 as f import numpy as np #----------------- 1(a) ---------------------------- seed = 1094801294865 print('The seed will be:',seed) #Initialize the RNG and plot the asked figures. R = f.RNG(seed) samp = R.sample(1000000) samp1000 = samp[:1000] sshift = samp[1:1001:1] f.scatter(sshift, samp1000, 'Sequential Random Numbers', r'$x_{i+1}$', r'$x_i$' ,'scatter1a1',True) f.scatter(np.linspace(0,1000,1000), samp1000, ' Random Numbers', 'i', r'$x_i$' ,'scatter1a2',True) #plot the histogram of the sample. f.plthist(samp, 20, 'Distribution of the RNG', 'Result', 'Probability','hist1a', True) np.savetxt('../seed.txt',R.state)
import matplotlib matplotlib.use('Agg') import numpy as np from matplotlib import pyplot as plt import functions21 as f R = f.RNG(np.loadtxt('../seed.txt')) #---------------------------- 1(b) -------------------------- #For the asked distribution values plot both the NormedGaussian and the #histogram of a sample. m = 3 s = 2.4 y1 = R.BoxMuller(1000, mu = m, sigma = s) xsG = np.linspace(m - 5 * s, m + 5 * s, 10000) ysG = f.NormedGaussian(xsG, mu = m, sig = s) plt.hist(y1, bins=21, density=True, label='RNG') plt.plot(xsG,ysG, label='Theoretical') for i in range(6): dx = i * s fval = f.NormedGaussian(m - dx, mu = m, sig = s) #Add the +-n\sigma-lines. plt.plot([m - dx, m - dx], [0,fval], c='black') plt.plot([m + dx, m + dx], [0,fval], c='black') #Plot the y-axis in 'log' to be able to see the lines clearly plt.yscale('log') plt.legend() plt.title(r'Normal distribution with $\mu=3$ and $\sigma=2.4$') plt.xlabel(r'$x$') plt.ylabel(r'$\mathbb{P}(x)$') plt.savefig('1b.png',format='png')
import matplotlib matplotlib.use('Agg') import functions24 as f4 import numpy as np from matplotlib import pyplot as plt import sys sys.path.append('../Problem1') import functions21 as f1 #Initialize an RNG and positions if 64 * 64 particles. R = f1.RNG(1246578543) print('seed for c =', 1246578543) xso, yso = [np.linspace(0, 63, 64) for i in range(2)] xso, yso = np.meshgrid(xso, yso) #Get the x- and y- components of S(q) from a Gaussian Random Field. Bx, By = f4.grf2d(R) #Counteract the normalization from scipy.fftpack. Bx, By = Bx.real * 64, By.real * 64 #Initialize the a-values and arrays to store x, y, p_x and p_y for the first #ten particles along the y-axis (for x=0 thus). aval = np.linspace(0.0025, 1, 30 * 3) da = aval[1] - aval[0] x10, y10, px10, py10 = [np.zeros((10, 90)) for i in range(4)] #Plot the initial positions and store the initial positions and momenta. fig = plt.figure(dpi=50, figsize=[6.4, 6.4]) plt.scatter(xso, yso, s=1, c='black')