Difference between revisions of "Binary Operators"

From LIBISIS
Jump to navigation Jump to search
m
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''UNDER CONSTRUCTION'''
 
 
----
 
 
 
 
The binary Operators are:
 
The binary Operators are:
  
Line 19: Line 14:
 
These are the functions
 
These are the functions
  
<pre> plus_x(a, b)
+
<pre>plus_x(a, b)
 
plus_y(a, b)
 
plus_y(a, b)
 
minus_x(a, b)
 
minus_x(a, b)
Line 39: Line 34:
  
 
'''''Example:'''''
 
'''''Example:'''''
 +
  
 
<tt>>> '''new_ww''' = plus_x('''ww''', '''n''')</tt>
 
<tt>>> '''new_ww''' = plus_x('''ww''', '''n''')</tt>
 +
  
 
Where '''n''' is a one dimensional array of objects and '''ww''' is an array of [[IXTdataset_2d]], will perform the operation
 
Where '''n''' is a one dimensional array of objects and '''ww''' is an array of [[IXTdataset_2d]], will perform the operation
 +
  
 
<tt>'''new_ww(i).signal(j,k)''' = '''ww(i).signal(j,k)''' + '''n(k)''' </tt>
 
<tt>'''new_ww(i).signal(j,k)''' = '''ww(i).signal(j,k)''' + '''n(k)''' </tt>
Line 48: Line 46:
  
 
===operation_y(a, b)===
 
===operation_y(a, b)===
 +
  
 
Where operation is plus, minus, times or divide,
 
Where operation is plus, minus, times or divide,
Line 55: Line 54:
  
 
'''''Example:'''''
 
'''''Example:'''''
 +
  
 
<tt>>> '''new_ww''' = '''new_ww''' = plus_y('''ww''', '''n''') </tt>
 
<tt>>> '''new_ww''' = '''new_ww''' = plus_y('''ww''', '''n''') </tt>
 +
  
 
Where '''n''' is a one dimensional array of objects and '''ww''' is an array of [[IXTdataset_2d]], will perform the operation
 
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)'''
+
 
 +
<tt>'''new_ww(i).signal(j,k)''' = '''ww(i).signal(j,k)''' + '''n(j)'''</tt>
  
  
Line 72: Line 74:
 
The operation is performed on each signal element and the single number such that
 
The operation is performed on each signal element and the single number such that
  
new_ww.signal(i,j) = ww.signal(i,j) + number
+
 
 +
<tt>new_ww.signal(i,j) = ww.signal(i,j) + number</tt>
  
  
 
'''''Example:'''''
 
'''''Example:'''''
 +
  
 
<tt>>> 2 – w</tt>
 
<tt>>> 2 – w</tt>
 +
  
 
* In this case, each signal element will be 2 – the signal element.  
 
* In this case, each signal element will be 2 – the signal element.  
Line 84: Line 89:
 
If the dataset is an array, then the operation is performed on every element of the array such that
 
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
+
 
 +
<tt>'''new_w(i)''' = '''w(i)''' + number</tt>
 +
 
  
 
Error data remains unchanged, since there is no error within a number.
 
Error data remains unchanged, since there is no error within a number.
Line 91: Line 98:
 
==Dataset and Row Vector of Numbers==
 
==Dataset and Row Vector of Numbers==
  
<pre>w + <b>n</b>
+
 
>> plus_x(ww, <b>n</b>)
+
w + <b>n</b>
>> plus_y(ww, <b>n</b>)</pre>
+
plus_x(ww, <b>n</b>)
 +
plus_y(ww, <b>n</b>)
 +
 
  
 
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
 
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:
+
<tt>'''new_signal'''(i,j) = '''signal'''(i,j) + '''number'''(j)</tt>
 +
 
 +
 
 +
'''''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.
 +
 
 +
 
  
>> [1, 2, 3, 4] / w1
+
===[[IXTdataset_2d]] Methods===
  
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.  
+
There are two ways to add a row vector to an [[IXTdataset_2d]].  
  
===operation_x Method===
 
  
>> plus_x(ww, n)
+
====operation_x Method====
>> plus_x(ww, n)
+
 
 +
 
 +
plus_x(ww, '''n''')
 +
plus_x(ww, '''n''')
 +
 
  
 
The signal data is operated on so that  
 
The signal data is operated on so that  
  
New_signal(i,j) = 2d.signal(i,j) / number(j)
 
  
===operation_y Method===
+
<tt>new_signal(i,j) = signal(i,j) / '''n'''(j)</tt>
 +
 
 +
 
 +
====operation_y Method====
 +
 
 +
 +
plus_y(ww, n)
 +
plus_y(ww, n)
  
>> plus_y(ww, n)
 
>> plus_y(ww, n)
 
  
 
The signal data is operated on so that
 
The signal data is operated on so that
  
New_signal(i,j) = 2d.signal(i,j) * n(i)
+
 
 +
<tt>New_signal(i,j) = 2d.signal(i,j) * '''n'''(i)</tt>
 +
 
  
 
===Arrays of Datasets===
 
===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
 
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
+
 
 +
<tt>'''new_w'''(i) = '''w'''(i) + '''number'''</tt>
 +
 
  
 
The error data remains unchanged.
 
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
+
==[[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
 +
 
 +
 
 +
<tt>new_signal(i,j) = signal(i,j) * '''number'''(i,j)</tt>
 +
 
 +
 
 +
'''''Example:'''''
 +
 
  
new_signal(i,j) = signal(i,j) * number(i,j)
+
<tt>new_ww = ww ^ [1,2,3; 4,5,6]</tt>
  
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.
  
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
+
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
+
 
 +
'''new_ww'''(i) = '''ww'''(i) / '''M'''
  
  
 
Error data is not changed.
 
Error data is not changed.
 +
  
 
==Dataset and Dataset==
 
==Dataset and Dataset==
  
>> ww + ww
+
ww + ww
>> ww + w
+
ww + w
>> ww + w
+
ww + '''w'''
>> w + w
+
w + w
>> plus_x(ww, w)
+
plus_x(ww, w)
>> plus_y(ww, w)
+
plus_y(ww, w)
>> plus_x(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
  
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)
+
<tt>new_signal(i,j) = a.signal(i,j) / b.signal(i,j)</tt>
 +
 
  
 
===Array of [[IXTdataset_1d]] Objects With a Single [[IXTdataset_2d]] Object===
 
===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!).
+
 
 +
 
 +
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====
 
====operation_x method====
  
>> plus_x(ww, w)
+
 
>> ww + w  
+
  plus_x(ww, '''w''')
 +
  ww + '''w'''
 +
 
  
 
The signal data is operated on so that
 
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.  
+
<tt>New_signal(i,j) = 2d.signal(i,j) * '''1d'''(i).signal(j)</tt>
  
 
===Single [[IXTdataset_1d]] With an [[IXTdataset_2d]]===
 
===Single [[IXTdataset_1d]] With an [[IXTdataset_2d]]===
  
====operation_x method====
 
  
>> plus_x(ww, w)
+
A single [[IXTdataset_1d]] can be operated on in one of two ways with an [[IXTdataset_2d]].
>> ww + w
+
 
 +
 
 +
====operation_x Method====
 +
 
 +
 
 +
plus_x(ww, w)  
 +
ww + w
 +
 
  
 
The signal data is operated on so that  
 
The signal data is operated on so that  
  
New_signal(i,j) = 2d.signal(i,j) / 1d.signal(j)
+
 
 +
<tt>New_signal(i,j) = 2d.signal(i,j) / 1d.signal(j)</tt>
 +
 
  
 
====operation_y method====
 
====operation_y method====
  
>> plus_y(ww, w)
+
 
 +
plus_y(ww, w)
 +
 
  
 
The signal data is operated on so that  
 
The signal data is operated on so that  
  
New_signal(i,j) = 2d.signal(i,j) / 1d.signal(i)
+
 
 +
<tt>New_signal(i,j) = 2d.signal(i,j) / 1d.signal(i)</tt>
 +
 
  
 
Associated errors are calculated using error addition methods.
 
Associated errors are calculated using error addition methods.
Line 205: Line 265:
 
==Dataset array and a Cell Array==
 
==Dataset array and a Cell Array==
  
>> ww + C
+
 
>> w + C
+
>> '''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.  
 
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}
+
'''''Example:'''''
 +
 
 +
 
 +
<tt>New_dataset(i) = dataset(i) / cellarray{i}</tt>
 +
 
 +
 
 +
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
  
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}
+
<tt>b = {d2d, '''d1d_array''', '''matrix''', number, '''row_vector'''}</tt>
  
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
+
Where d2d is another [[IXTdataset_2d]] and d1d_array is an array of [[IXTdataset_1d]]. Then the minus operation can be applied like so
 +
 
 +
 
 +
<tt>ww_new =  ww - b</tt>
 +
 
  
 
This would be the same as
 
This would be the same as
  
>> ww(1) – d2d
+
 
>> ww(2) – d1d_array
+
>> '''ww_new'''(1) =  '''ww'''(1) – d2d
>> ww(3) – matrix
+
>> '''ww_new'''(2) =  '''ww'''(2) – '''d1d_array'''
>> ww(4) – number
+
>> '''ww_new'''(3) = '''ww'''(3) – '''matrix'''
>> ww(5) – row_vector
+
>> '''ww_new'''(4) = '''ww'''(4) – number
 +
>> '''ww_new'''(5) =  '''ww'''(5) – '''row_vector'''

Latest revision as of 16:01, 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:


>> 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