| Function Prototype | Description | ||
| y | = | floor(my.a) | smallest element of array |
| y | = | ceil(my.a) | largest element of array |
| y | = | vsum(my.a) | sum of all elements of array |
| y | = | vprod(my.a) | product of all elements of array |
| y | = | npts(my.a) | number of elements in array |
| my.y | = | indarr(n) | generate array 1, 2, ..., n |
| my.y | = | ones(n) | generate array of n ones |
| my.y | = | zeros(n) | generate array of n zeros |
| my.y | = | range(start,stop,step) | generate array over a given range |
| my.y | = | join(my.x1,my.x2) | concatenate 2 arrays |
| my.y | = | slice(my.x,n1,n2) | generate sub-array my.x[n1:n2] |
| n | = | nofx(my.x,x) | index of my.x with value closest to x |
As mentioned above, when arrays are used in expression, the result is usually an array. In addition, the functions listed in Tables 2 are designed especially to work with arrays, and may either create arrays given a few scalars or return a scalar given an array expressions. For example, the functions ceil(), floor(), vsum(), vprod(), and npts() each return a scalar given an array argument. ceil() and floor() give the maximum and minimum element of the array, respectively. vsum() returns the sum of all elements of an array, vprod() returns the product of all the elements, and npts() returns the number of points in an array. As with all functions, these can be used on expressions as well as on named arrays. Note that ceil() is different from max(), as ceil() returns the single largest value of an array, while max() returns the larger of two values. The functions floor() and min() are not the same.
As mentioned earlier, there are a number of functions to help build arrays from scratch. The function indarr() takes one scalar argument as an array length and fills the array with integers: 1, 2, 3, .... For example
Ifeffit> my.index = indarr(10)will fill my.index be the array (1, 2, 3, ..., 10). The functions ones() and zeros() create arrays of a specified length, only the created arrays will have all elements set to 1 and 0, respectively. Of course, these functions can be used anywhere in a math expression:
Ifeffit> my.xval = 1 + indarr( max(x1,1) ) /100It is an error to give these functions an argument that evaluates to less than 1. If the argument to one of these three functions is itself an array, the first element will be used as the dimension, and the rest of the array will be ignored.
The function range() is a more general function for creating evenly spaced arrays. It takes three arguments: a starting value, a stopping value, and a step size for the array. That is
Ifeffit> my.x = range(3,10,1)will create the array (3, 4, 5, ...10), and
Ifeffit> my.x = range(2,4,0.1)will create an array with values (2,2.1,2.2,..., 3.8,4.0). If the range is not an exact multiple of the step size, range() will make sure all elements of the array are within the range specified by the start and stop values. Negative step sizes are allowed, but should be used with care.
Arrays can also be built up and broken apart using the join(), slice(), and nofx() functions. The join() function concatenates two arrays, for example
Ifeffit> my.x1 = indarr(3) Ifeffit> my.x2 = range(10,16,1.5) Ifeffit> my.x = join(my.x1,my.x2) Ifeffit> print my.x 1.0000 2.0000 3.0000 10.0000 11.5000 13.0000 14.50000 16.0000The slice() function will select a sub-array, or portion of the array defined by indices for the first and last point desired. Counting of indices begins with 1, so that
Ifeffit> my.x1 = indarr(10) Ifeffit> my.x2 = slice(my.x1,3,6) Ifeffit> print my.x2 3.0000 4.0000 5.000 6.0000The function nofx() will return the index of an array nearest to a given scalar value:
Ifeffit> my.x1 = range(90,180,9) Ifeffit> nx = nofx(my.x1,126) Ifeffit> print my.x1 90.0000 99.0000 108.000 117.000 126.000 135.000 144.000 153.000 162.000 171.000 180.000 Ifeffit> print nx 5.0000If multiple values in the array match (or are equally close to) the requested scalar, the first occurrence of ``the closest value'' will be reported.
| Function Prototype | Description | ||
| my.y | = | deriv(my.x) | finite-difference derivative of array |
| my.y | = | smooth(my.x) | three-point smoothing of array |
| my.y | = | interp(old.x,old.y,my.x) | linear interpolation of arrays |
| my.y | = | qinterp(old.x,old.y,my.x) | quadratic interpolation of arrays |
| my.y | = | splint(old.x,old.y,my.x) | spline interpolation of arrays |
| my.y | = | rebin(old.x,old.y,my.x) | re-binning interpolation of arrays |
| my.z | = | lconvolve(my.x,my.y,sigma) | convolve data with Lorentzian |
| my.z | = | gconvolve(my.x,my.y,sigma) | convolve data with Gaussian |
| y | = | debye(temp,theta) | |
| y | = | eins(temp,theta) | |