This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
The angle is expressed in radians.
The absolute value of the argument, or of each element of the argument, should be less than or equal to 1.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
The argument, or each element of the argument, should be equal to or larger than 1.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
The angle is expressed in radians.
The absolute value of the argument, or of each element of the argument, should be less than or equal to 1.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
The angle is expressed in radians.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
The absolute value of the argument, or of each element of the argument, should be less than 1.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function is equivalent to the INQUIRE_FILE procedure call.
The argument must be of type String.
The argument, or, in case of an argument of type matrix or histogram, all elements of the argument, should be less than the compilation parameter EXPMAX. An exponential overflow error condition is raised if this condition is not fulfilled. The exponential of an argument or an element of the argument less than -EXPMAX will be set to 0 if the IGNORE-EXPONENTIAL-UNDERFLOW option has been set. Otherwise an exponential underflow error condition is raised.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
The argument, or each element of the argument, should be larger than 10\<SUP\>-20\</SUP\> and smaller than 25. In expressions where the \Γ-function is cancelled in part by other exponentials, and in which arguments larger than 25 are required, one should use the LOG_GAMMA function.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
The function returns Nill, of type Undefined, if there is no such global variable.
Example:
Global i=1 Do If type(global(`SEL_`/string(i)))#`Histogram` Then Leave Call write_histogram_rz(global(`SEL_`/string(i)),`arrival.rz`) Global i=i+1 Enddo
The ARRIVAL-TIME-DISTRIBUTION command can create a set of histograms which are numbered SEL_1, SEL_2 etc. These histograms are written to an RZ file by the above set of instructions. The TYPE and GLOBAL functions are used to stop the loop as soon as the last histogram has been written.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
The argument, or each element of the argument, should be larger than 0.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function is used when the \Γ-function itself can't be evaluated without numerical overflow, but when the overflow in the expression as a whole is cancelled by other terms. If the argument is in the range [10\<SUP\>-20\</SUP\>,25], then one would normally use the GAMMA function directly.
The argument, or each element of the argument, should be strictly positive.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
When given an Histogram, it will return the coordinate of the upper edge for the last bin. Using this function with an Histogram is equivalent to calling the INQUIRE_HISTOGRAM procedure and using its maximum argument.
When given a Matrix as argument, it will return the largest value found in the Matrix. To obtain the indices of the maximum, use the LOCATE_MAXIMUM procedure call.
The function returns in either case a value of type Number.
Using this function with an Histogram is equivalent to calling the INQUIRE_HISTOGRAM procedure and using its mean argument.
This function accepts Matrices with any number of dimensions.
The mean is for both Histograms and Matrices defined as:
\Σ x mean = --- n
The function returns in either case a value of type Number.
Example:
See the RMS function.
When given an Histogram, it will return the coordinate of the lower edge for the first bin. Using this function with an Histogram is equivalent to calling the INQUIRE_HISTOGRAM procedure and using its minimum argument.
When given a Matrix as argument, it will return the smallest value found in the Matrix. To obtain the indices of the minimum, use the LOCATE_MINIMUM procedure call.
The function returns in either case a value of type Number.
Example: finding the smallest of a set of numbers
Global x1 = 2 Global x2 = 3 Global x3 = 1 Global x4 = 1.5 Global xmin = minimum(x1 & x2 & x3 & x4) Say "The smallest of the numbers ({x1,x2,x3,x4}) is {xmin}."
The function takes a Logical are argument and returns a Logical.
If the argument is a String, it should contain a simple number, not an expression.
If the argument is a Matrix, then its first element will be returned.
Use the ZEROES function to create a vector than contains 0 everywhere and the ROW function if you wish to create a vector that contains the numbers 1, 2, 3 ...
The function returns in either case a value of type Number.
This is the reverse operation of the REF_HISTOGRAM, REF_MATRIX and REF_STRING.
Internally however, the bookkeeping of histograms and of global variables are separated, and it is common that histograms exist which have no associated global. In the rare event that one wishes to access these histograms one uses REF_HISTOGRAM.
REF_HISTOGRAM takes a Number as argument which is interpreted as the number of the histogram in the histogram buffer. The numbers of the histograms can be found in the first column of the output of the LIST_HISTOGRAMS procedure.
Example:
Call delete_histogram Call book_histogram(a,25,`integer`) For i From 1 To 10000 Do Call fill_histogram(a,rnd_poisson(3)) Enddo Call plot_histogram(ref_histogram(1)) Call plot_end
By first calling DELETE_HISTOGRAM, we are sure that the next histogram to be booked will have number 1. This histogram is in this case also known as A. It is filled and then plotted, using its number rather than its associated global.
Such access is rarely required since all user-relevant Matrices can in principle be accessed via a Global variable.
Such access is rarely required since all user-relevant Strings can in principle be accessed via a Global variable.
Example:
Global evec = 10000 & 15000 & 25000 & 50000 For e In reverse(evec) Do Say {e} EnddoIn this example, a vector EVEC is filled with 4 elements. The loop over this vector starts from the last element.
Using this function with an Histogram is equivalent to calling the INQUIRE_HISTOGRAM procedure and using its rms argument.
This function accepts Matrices with any number of dimensions.
The RMS is for both Histograms and Matrices defined as:
\Σ(x\²) - \Σ\²(x)/n RMS\² = --------------- n
The function returns in either case a value of type Number.
Example:
Call book_histogram(a,100) Call book_matrix(b,10000) For i From 1 To 10000 Do Global entry=rnd_gauss Call fill_histogram(a,entry) Global b[i]=entry Enddo Say "Histogram mean: {mean(a)}, rms: {rms(a)}" Say "Matrix mean: {mean(b)}, rms: {rms(b)}"
A test to verify that the mean and RMS for matrices and histograms coincide. This should be numerically exact since the mean and RMS for histograms are computed from the entries, not from the bin contents.
The optional argument specifies the mean (and the standard deviation) of the distribution to be generated. If the argument is omitted, a mean of 1 is assumed.
The mean is usually specified as a Number but may also be of type Histogram and Matrix. In the latter two cases, variables of the same type will be returned, taking for each output element as mean the corresponding element of the argument.
A random number sequences according to only one function can be generated at the time.
This generator has no arguments.
This function has no arguments.
\Γ(x,p) = x\<SUP\>p-1\</SUP\> e\<SUP\>-x\</SUP\> / (p-1)!Three special cases deserve to be mentioned:
The shape parameter p is usually specified as a Number but may also be of type Histogram and Matrix. In the latter two cases, variables of the same type will be returned, taking for each output element as shape parameter the corresponding element of the argument.
Example:
Call book_histogram(hrnd,100,0,5) For i From 1 To 100000 Do Call fill_histogram(hrnd,rnd_gamma(2)) Enddo Call plot_histogram(hrnd) Call plot_end
This function has no arguments.
A companion random number generator, RND_VAVILOV, is available as a procedure call. This generator is to be used when typical single-interaction energy losses are small compared with the kinematic maximum energy loss.
P = exp(-x/w)/(2w) for x>0 exp(+x/w)/(2w) for x<0
The optional argument w acts as a multiplicative scaling.
Example:
Call book_histogram(hl,100,-8,8) For i From 1 To 100000 Do Call fill_histogram(hl,rnd_laplace(1)) Enddo Call plot_histogram(hl,`x`,`Laplace distribution`) Call plot_endWhich should produce this plot:
Separate random number sequences according to different histograms can be generated concurrently.
The procedure works by creating a cumulative histogram and reverse-interpolating it for a uniformly distributed random number. Failures can occur for the following reasons:
The argument is mandatory.
Example:
// Generate an electron energy spectrum. magboltz xenon 90 co2 10 e-field 250 coll 1 keep// This results in a set of arrays, E_1 and F_1 in particular. // These arrays are typically too long to be used directly as // histograms and need therefore to be rebinned. Global bin=5 Call book_matrix(he,entier(size(f_1)/bin)) Call book_matrix(hf,entier(size(f_1)/bin)) For i From 1 To size(hf) Do Global he[i]=0 Global hf[i]=0 For j From 1 To bin Do Global he[i]=he[i]+e_1[bin*(i-1)+j] Global hf[i]=hf[i]+f_1[bin*(i-1)+j] Enddo Global he[i]=he[i]/bin Global hf[i]=hf[i]/bin Enddo
// Convert the rebinned array to a histogram Call matrix_to_histogram(hf, number(he[1]), number(he[size(he)]), histf)
// Book an histogram with identical parameters Call book_histogram(check, size(hf), number(he[1]), number(he[size(he)]))
// And generate 10000 samples For i From 1 To 10000 Do Call fill_histogram(check, rnd_histogram(histf)) Enddo Global check = check * sum(histf)/sum(check)
// Compare Call plot_graph(he,hf) Call plot_line(e_1,f_1,`function-2`) Call plot_histogram(histf, ``,``, `noframe`) Call plot_histogram(check, ``,``, `noframe`) Call plot_end
-mean n e mean P(n) = ------------- n!
The optional argument of this generator specifies the mean of the distribution to be generated. If the argument is omitted, a mean of 1 is assumed.
This procedure calls the CERN library routine RNPSSN.
The mean is usually specified as a Number but may also be of type Histogram and Matrix. In the latter two cases, variables of the same type will be returned, taking for each output element as mean the corresponding element of the argument.
Example:
Global mean=4.2 Global nrndm=10000Call book_histogram(p,20,-0.5,19.5) For i From 1 To nrndm Do Call fill_histogram(p,rnd_poisson(mean)) Enddo
Global mu=mean(p) Global scale=sum(p)
Call fit_function(p,`scale*exp(-mu)*mu^x/gamma(x+1)`, ... mu,scale,emu,escale,`plot,print`)
Say "Fitted mean: {mu} +/- {emu}, Histogram mean: {mean}, True: {mean}" Say "Contents: {scale} +/- {escale}, True: {nrndm}"
After having filled an histogram (note the binning) with Poisson random numbers, we wish to verify the generator. This we do by computing the MEAN and we also do a fit using FIT_FUNCTION. For the initial guess of the parameters we use the mean and the SUM.
This example only works for small values of the mean since the GAMMA function does not accept large arguments. To make it work for larger means, one uses the LOG_GAMMA function:
Global mean=50 Global nrndm=10000Call book_histogram(p,100,-0.5,99.5) For i From 1 To nrndm Do Call fill_histogram(p,rnd_poisson(mean)) Enddo
Global mu=mean(p) Global scale=sum(p)
Call fit_function(p,`scale*exp(x*log(mu)-log_gamma(x+1)-mu)`, ... mu,scale,emu,escale,`plot,print`)
Say "Fitted mean: {mu} +/- {emu}, Histogram mean: {mean}, True: {mean}" Say "Contents: {scale} +/- {escale}, True: {nrndm}"
The argument specifies the \θ parameter of the distribution to be generated. If the argument is omitted, a \θ of 1 is assumed.
This procedure calls the CERN library routine RNGAMA.
The \θ parameter is usually specified as a Number but may also be of type Histogram and Matrix. In the latter two cases, variables of the same type will be returned, taking for each output element as \θ the corresponding element of the argument.
This procedure calls the CERN library routine RANLUX.
The scaling factor is usually specified as a Number but may also be of type Histogram and Matrix. In the latter two cases, variables of the same type will be returned, taking for each output element as mean the corresponding element of the argument.
The description of the FIT_GAUSSIAN procedure shows an example of the use of RND_UNIFORM.
[The default scaling factor is 1.]
Use the ZEROES and ONES functions if you wish to create a vector that contains only 0 or only 1.
Examples:
Global xmin=2 Global xmax=23 Global nx=200 Global xlin=xmin+(xmax-xmin)*(row(nx)-1)/(nx-1) Global xlog=xmin*(xmax-xmin)^((row(nx)-1)/(nx-1))
This generates series of nx equally and logarithmically spaced points between xmin and xmax.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
Use the DIMENSIONS procedure to obtain more detailed information about the structure of the matrix.
This function is of use if you need to loop over the elements of a 1-dimensional matrix in order to apply an operation which is not available via the operators and procedure calls, e.g.:
For i From 1 To size(a) Do If a[i]>0 Then Global i0=i Leave Endif Enddo
This finds the first strictly positive element in a matrix.
The argument, or each element of the argument, should be equal to or larger than 0.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
The STRING function is for instance used to create file names that depend on parameters of the chamber being studied:
Global argon 70 Global co2 30 Global gas_file `argon_`/string(argon)/`_CO2_`/string(co2)/`.gas` Call inquire_file(gas_file,exist) If exist Then get {gas_file} Else write {gas_file} magboltz argon {argon} co2 {co2} Endif
The function returns in either case a value of type Number.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function can take either an Histogram, a Matrix or a Number as argument. The function acts bin-by-bin on Histograms and element-by-element on Matrices and returns a value of the same type as the argument.
This function provides a functionality which is similar to the INQUIRE_TYPE procedure. The main difference is that it is permissible to give the INQUIRE_TYPE procedure as first argument a variable that does not yet exist while this is not allowed with the TYPE function. The reason for this is that the arguments of procedures are automatically declared if they do not yet exist, while the arguments of functions must be existing variables. If you wish to use the TYPE function and are not sure the variable exists, then use the GLOBAL function.
Examples:
Global a `Hello !` Say {type(a)} Say {type(global(`A`))}Say {type(global(`does not exist`))}
Both Say statements in the first example will display "String", which is the type the variable A gets by executing the Global statement.
The argument of the GLOBAL function in the second example is not a valid name for a global variable, GLOBAL will therefore return Nill, of type Undefined.
Use the ONES function to create a vector than contains 1 everywhere and the ROW function if you wish to create a vector that contains the numbers 1, 2, 3 ...
Do not confuse this function with the ZEROES procedure.
Formatted on 21/01/18 at 16:55.