Manipulating Arrays
Use AEL to manipulate arrays when you create AEL functions to generate ideal coefficients for designing custom filters. For details on using AEL, refer to the AEL documentation. For details on importing an AEL function you have created, refer to Importing an AEL Ideal Coefficients Function.
Declaring and Initializing Arrays
AEL supports multidimensional arrays using the following conventions.
- Array values are enclosed in curly braces "{ }"
- Array elements are separated by commas ","
- Array elements may be integers, doubles, or complex numbers
- Sequences can be used to initialize an integer or double array
- Matrices (enclosed within brackets "[ ]") can be assigned by separating rows by semicolons ";" and elements within rows by commas ","
Example:
// one dimension (row vectors) decl x = {1+3i, 4-5i, 9+3i, 10i}; x = [1+3i, 4-5i, 9+3i, 10i]; x = {1::10} // x = {1,2,3,4,5,6,7,8,9,10} x = {1::2::.5} // x = {1,1.5,2} // column vectors decl z; z = {{1},{2},{3}}; z = [1;2;3]; // two dimension (matrix) decl y; y = { {1,2}, {3,4}, {5,6}, {7,8} }; y = [ 1,2; 3,4; 5,6; 7,8 ]; // three dimension decl s; s = {[0,1;2,3],[4,5;6,7]}; s = {{{0,1},{2,3}}, {{4,5},{6,7}}};
Displaying Arrays
Use the following function to display and print arrays during the debugging process.
identify_value();
This function converts the value assigned to a variable (or array) to a string. This value can then be printed using an output function such as fprintf .
Example :
decl x= {1+3i, 4-5i, 9+3i, 10i};
fprintf(stdout, "%s\n", identify_value(x));
// this would output "{1+3i, 4-5i, 9+3i, 10i}"
decl y= {{1,2},{3,4},{5,6},{7,8}};
fprintf(stdout, "%s\n", identify_value(y));
// this would output "{{1,2},{3,4},{5,6},{7,8}}"
Accessing Array Elements
To access elements within an array, specify the array name followed by the indexes enclosed in square brackets "[ ]".
To access elements of multidimensional arrays:
- The indices may be separated by commas and the whole sequence enclosed in square brackets as follows: [1,3]
- Each index may be enclosed in square brackets as follows: [1][3]
- An index may be an AEL sequence as follows: [1::3]
Example:
// x's 2nd element is modified to a new value x[1] = 10-10i; // an element in y is printed, the value printed is "4" fprintf(stderr, "%s",identify_value(y[1,1])); // an element in y is changed from "7" to "50" y[3][0] = 50; // this loop produces the sum of all elements of x sum = 0; for ( i=0; i<4; i++) sum += x[i];
Array Operations
Assignments, additions, subtraction, multiplication (which is essentially matrix multiplication), division, and negation are some of the operations that may be performed on a whole array.
Example:
decl x = {1,2,3,4};
// z = {1,2,3,4}
decl z = x;
// x = {1,2,3,4} and z = {5,5}
z = {5,5};
| Note Unlike C arrays, when assignments are made in AEL arrays, the receiver of the assignment points to the original array. And when modifications are made to an array, a new array is created so that other variables pointing to that array are not modified. |
Addition and Subtraction
When addition or subtraction is executed between whole arrays, the math is executed one element at a time. Therefore, the array bounds must be exactly the same. Element by element multiplication, division, and power are also supported by using the operators ., ./, and .*.
Example:
decl x = {1,2,3,4};
decl y = {9,8,7,6};
// z = {10,10,10,10};
decl z = x + y;
x = { {1,2}, {3,4} };
y = { {10,9}, {8,7} };
// z = { {-9,-7}, {-5,-3} };
z = x - y;
// z = {9,16,21,24}
z = x .* y;
Multiplication
When multiplication is executed between whole arrays, matrix multiplication is executed. Therefore, the arrays must be two dimensional and the array bounds must be compatible for matrix multiplication, which is row1 x col1 * row2 x col2 where col1 must equal row2 and the new array will have the dimensions row1 x col2 .
Example:
x = { {1,2}, {3,4} };
y = { {10,9}, {8,7} };
// z = { {26,23}, {62,55} };
z = x * y;
| Note The following shorthand notations are supported: +=, -=, *= |
Scalars and Arrays
Any math operation between an array and scalar values is legal. The result of such expressions is an array.
Example:
decl x = {1,2,3,4};
// x = "{6,7,8,9}"
x += 5;
// x = "{32,28,24,22}"
x = 100 / x * 2;
Transposing Arrays
Transposition of arrays is supported using the following syntax.
Example:
decl x = {1,2,3,4};
// x = {{1},{2},{3},{4}}
y = x';
| Note Several built-in math functions are also available for operation on arrays. These include functions such as sin, cos, tan, asin, acos, atan, etc. For details on the math functions available within AEL, refer to the "Math Functions" section in the AEL documentation. |
Privacy
Statement
|
Terms of Use
|
Legal |
Contact Us
|
© Agilent 2000-2008 ![]()