I got a code in Python that I will write it again in Matlab and get the same plot:
The code is :
npts = 1000 # number of points in uncorrelated data setEmax = 10. # energy goes from zero to EmaxEc = 0.1 # correlation energykT = 0.25# create discrete values of EnergyE = np.linspace(0, Emax, npts)E_extra = np.linspace(0, Emax, 2*npts-1) #sometimes we need this size to convolve#PLOT 1: Tbar correlatedTbar = np.random.normal(loc=0., scale=1.0, size=2*npts-1 )y = np.exp(- ((E-Emax/2.)/Ec)**2)#convolution between Tbar and correlation energyTbar_c = np.convolve(y, Tbar, mode='valid') #valid = no edge effects# normalize the data (maximum=1, minimum=0)Tbar_c = Tbar_c - Tbar_c.min()Tbar_c = Tbar_c/Tbar_c.max()# plot the correlated data setax1.plot(E, Tbar_c)
The plot is (I need the first plot (the one at the top T(E)))
Here is what I have done yet:
clcclear allEmax=10;Ec=0.01;E=0:0.01:10;g=exp(-0.5.*((E-Emax).^2)./Ec);y=rand(1,length(E));%y=rand(size(E))
T1=conv(y,g,'same');T=T1./norm(T1);subplot(3,1,1);plot(E,T)
The problem is for me here:
Draw random samples from a normal (Gaussian) distribution. in Python we can do it by :
Tbar = np.random.normal(loc=0., scale=1.0, size=2*npts-1 )
Best Answer