Difference between revisions of "Binary Operators"
m |
|||
Line 1: | Line 1: | ||
− | + | The binary Operators are: | |
− | + | <pre>>> a + b | |
+ | >> a – b | ||
+ | >> a / b | ||
+ | >> a * b | ||
+ | >> a ^ b</pre> | ||
+ | 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 | |
− | |||
− | |||
− | |||
− | |||
− | |||
+ | <pre>>> 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)</pre> | ||
− | + | 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:''''' |
− | >> | + | <tt>>> plus_x('''ww''', '''n''')</tt> |
+ | Where n is a one dimensional array of objects and ww is an array of [[IXTdataset_2d]], gives | ||
− | + | new_ww(i).signal(j,k) = ww(i).signal(j,k) + a(k) | |
+ | Similarly, | ||
− | + | >> 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 i.e. | |
+ | >> plus_y(ww, n) | ||
− | + | Where n is a one dimensional array of objects and ww is an array of IXTdataset_2d, gives | |
− | + | new_ww(i).signal(j,k) = ww(i).signal(j,k) + a(j) | |
− | + | And the following 3 commands are equivalent | |
+ | >> plus_x(ww, 5) | ||
+ | >> plus_y(ww, 5) | ||
+ | >> ww + 5 | ||
− | + | Since 5 is a single number and not a 1 dimensional array. | |
+ | 4.4.2 Dataset and a Single number | ||
− | + | >> w + n | |
+ | >> ww + n | ||
+ | >> plus_x(ww, n) | ||
+ | >> plus_y(ww, n) | ||
+ | The operation is performed on each signal element and the single number such that | ||
− | + | new_signal(i,j) = signal(i,j) + number | |
+ | |||
+ | For 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. | ||
+ | |||
+ | 4.4.3 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) | ||
+ | |||
+ | For example: | ||
+ | |||
+ | >> [1, 2, 3, 4] / w1 | ||
+ | |||
+ | 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. | ||
+ | |||
+ | 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) = 2d.signal(i,j) / number(j) | |
− | |||
− | + | operation_y method | |
− | new_signal(i,j) = signal(i,j) + number | + | >> 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. | ||
+ | 4.4.4 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) | ||
+ | |||
+ | For 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) / matrix | ||
+ | |||
+ | |||
+ | Error data is not changed. | ||
+ | |||
+ | 4.4.5 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) | ||
+ | |||
+ | 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) | ||
+ | |||
+ | Also, 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. | ||
+ | 4.4.6 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. | ||
+ | |||
+ | For 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 - b | ||
+ | |||
+ | This would be the same as | ||
+ | |||
+ | >> ww(1) – d2d | ||
+ | >> ww(2) – d1d_array | ||
+ | >> ww(3) – matrix | ||
+ | >> ww(4) – number | ||
+ | >> ww(5) – row_vector |
Revision as of 15:05, 31 March 2008
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:
>> plus_x(ww, n)
Where n is a one dimensional array of objects and ww is an array of IXTdataset_2d, gives
new_ww(i).signal(j,k) = ww(i).signal(j,k) + a(k)
Similarly,
>> 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 i.e.
>> plus_y(ww, n)
Where n is a one dimensional array of objects and ww is an array of IXTdataset_2d, gives
new_ww(i).signal(j,k) = ww(i).signal(j,k) + a(j)
And the following 3 commands are equivalent
>> plus_x(ww, 5) >> plus_y(ww, 5) >> ww + 5
Since 5 is a single number and not a 1 dimensional array.
4.4.2 Dataset and a Single number
>> w + n >> ww + n >> plus_x(ww, n) >> plus_y(ww, n)
The operation is performed on each signal element and the single number such that
new_signal(i,j) = signal(i,j) + number
For 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.
4.4.3 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)
For example:
>> [1, 2, 3, 4] / w1
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.
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) = 2d.signal(i,j) / number(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. 4.4.4 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)
For 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) / matrix
Error data is not changed.
4.4.5 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)
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)
Also, 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. 4.4.6 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.
For 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 - b
This would be the same as
>> ww(1) – d2d >> ww(2) – d1d_array >> ww(3) – matrix >> ww(4) – number >> ww(5) – row_vector