Binary Operators

From LIBISIS
Revision as of 16:01, 31 March 2008 by Dean Whittaker (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The binary Operators are:

 a + b
 a – b
 a / b
 a * b
 a ^ b

All operators act in a similar, intuitive way. There are many different kinds of objects which can be operated on. The list below gives the most general case wherever possible (i.e. does not distinguish IXTdataset_1d from IXTdataset_2d). Remember that the signal (and error) data in an IXTdataset_1d can be thought of as a single row of data, while the signal data in an IXTdataset_2d can be thought of as a matrix, with x data corresponding to the columns and y data to the rows. Here bold represents an array, w an IXTdataset_1d and ww an IXTdataset_2d.

operation_x and operation_y

These are the functions

plus_x(a, b)
plus_y(a, b)
minus_x(a, b)
minus_y(a, b)
times_x(a, b)
times_y(a, b)
divide_x(a, b)
divide_y(a, b)

These functions are methods of IXTdataset_2d objects.


operation_x(a, b)

Where operation is plus, minus, times or divide.

This forces any operation with a linear array to operate on the x rows of the signal data of the IXTdataset_2d object separately. Otherwise, this operation is the same as the normal operator


Example:


>> new_ww = plus_x(ww, n)


Where n is a one dimensional array of objects and ww is an array of IXTdataset_2d, will perform the operation


new_ww(i).signal(j,k) = ww(i).signal(j,k) + n(k)


operation_y(a, b)

Where operation is plus, minus, times or divide,

forces any operation with a linear array to operate on the y rows of the signal data of the IXTdataset_2d object separately. Otherwise, this operation is the same as the normal operator


Example:


>> new_ww = new_ww = plus_y(ww, n)


Where n is a one dimensional array of objects and ww is an array of IXTdataset_2d, will perform the operation


new_ww(i).signal(j,k) = ww(i).signal(j,k) + n(j)


Dataset and a Single number

 w + n
 ww + n


The operation is performed on each signal element and the single number such that


new_ww.signal(i,j) = ww.signal(i,j) + number


Example:


>> 2 – w


  • In this case, each signal element will be 2 – the signal element.


If the dataset is an array, then the operation is performed on every element of the array such that


new_w(i) = w(i) + number


Error data remains unchanged, since there is no error within a number.


Dataset and Row Vector of Numbers

w + n
plus_x(ww, n)
plus_y(ww, n)


If given a row vector of numbers of the length of the x array in an IXTdataset_1d, the operation will be performed on each signal element and the corresponding element in the array such that


new_signal(i,j) = signal(i,j) + number(j)


Example:


>> new_dataset = [1, 2, 3, 4] / w


  • Here, assuming w1 only has 4 signal elements and is an IXTdataset_1d, the first element of the signal array in the result will be 1/w1.signal(1), the second element 2/w1.signal(2), and so on.


IXTdataset_2d Methods

There are two ways to add a row vector to an IXTdataset_2d.


operation_x Method

plus_x(ww, n)
plus_x(ww, n)


The signal data is operated on so that


new_signal(i,j) = signal(i,j) / n(j)


operation_y Method

plus_y(ww, n)
plus_y(ww, n)


The signal data is operated on so that


New_signal(i,j) = 2d.signal(i,j) * n(i)


Arrays of Datasets

If the dataset is an array, then the operation is performed on each element in the dataset array. If the dimensions do not match for any part of the array, a warning will be given along with a blank dataset, but the operation will still be performed on the rest of the array such that


new_w(i) = w(i) + number


The error data remains unchanged.


==IXTdataset_2d and Matrix of Numbers


ww + M


An IXTdataset_2d can be operated on with a matrix of numbers. The number of columns must be equal to the length of the x array in the dataset and the number of rows equal to the length of the y array. Each element in the matrix is operated on with the corresponding element in the signal data so that


new_signal(i,j) = signal(i,j) * number(i,j)


Example:


new_ww = ww ^ [1,2,3; 4,5,6]


  • The length of x in ww must be 3, the length of y must be 2.


As with the vector case for IXTdataset_1d, if an array of IXTdataset_2d is operated on then the operation will apply to each IXTdataset_2d in turn, for example


new_ww(i) = ww(i) / M


Error data is not changed.


Dataset and Dataset

ww + ww
ww + w
ww + w
w + w
plus_x(ww, w)
plus_y(ww, w)
plus_x(ww, w)


If their dimensions and units agree (or one has no units), then datasets can be operated on together. In the case where the datasets are of the same type (i.e. two IXTdataset_2d datasets or two IXTdataset_1d datasets) then the signal data is simply operated on such that


new_signal(i,j) = a.signal(i,j) / b.signal(i,j)


Array of IXTdataset_1d Objects With a Single IXTdataset_2d Object

An array of IXTdataset_1d can be operated on with a single IXTdataset_2d in one way only (there is no operation_y method for this!).


operation_x method

 plus_x(ww, w)
 ww + w


The signal data is operated on so that


New_signal(i,j) = 2d.signal(i,j) * 1d(i).signal(j)

Single IXTdataset_1d With an IXTdataset_2d

A single IXTdataset_1d can be operated on in one of two ways with an IXTdataset_2d.


operation_x Method

plus_x(ww, w) 
ww + w


The signal data is operated on so that


New_signal(i,j) = 2d.signal(i,j) / 1d.signal(j)


operation_y method

plus_y(ww, w)


The signal data is operated on so that


New_signal(i,j) = 2d.signal(i,j) / 1d.signal(i)


Associated errors are calculated using error addition methods.


Dataset array and a Cell Array

>> ww + C >> w + C


If given a dataset array and a cell array, the operation is performed on each element of the dataset array and the corresponding element of the cell array in turn, the rules above are applied each time.


Example:


New_dataset(i) = dataset(i) / cellarray{i}


This method can be used to apply the same operation on different datasets and number types at the same time. For example, if ww is an IXTdataset_2d array of length 5 then a cell array can be constructed


b = {d2d, d1d_array, matrix, number, row_vector}


Where d2d is another IXTdataset_2d and d1d_array is an array of IXTdataset_1d. Then the minus operation can be applied like so


ww_new = ww - b


This would be the same as


>> ww_new(1) =  ww(1) – d2d
>> ww_new(2) =  ww(2) – d1d_array
>> ww_new(3) = ww(3) – matrix
>> ww_new(4) = ww(4) – number
>> ww_new(5) =  ww(5) – row_vector