music |
OSdata.com |
matrix
summary
This subchapter looks at matrices or two dimensional arrays.
free computer programming text book projecttable of contents
|
music |
OSdata.com |
This subchapter looks at matrices or two dimensional arrays.
free computer programming text book projecttable of contents
|
This subchapter is a stub section. It will be filled in with instructional material later. For now it serves the purpose of a place holder for the order of instruction.
Professors are invited to give feedback on both the proposed contents and the propsed order of this text book. Send commentary to Milo, PO Box 1361, Tustin, California, 92781, USA.
This subchapter looks at matrices or two dimensional arrays.
All arrays in LISP must be declared before they are used.
LISP ARRAY(x) LISP function that takes three or more arguments of type name, type, and dimnsions, and creates an array of that name, type, and dimensions.
(ARRAY TWODIMENSIONS FIXNUM 1024 1024)
The example creates a LISP array named TWODIMENSIONS that can contain fixed point numbers. The array elements are numbered by two indices, both in the range of 0 to 1,023.
The storage of a signle dimension array in memory is obvious: a linear sequence of memory locations (possibly with padding for instruction alignment purposes).
When an array has two or more dimensions, it is still ultimately stored in a linear sequence of memory locations (possibly with padding for instruction alignment purposes), but the dimensions must be lined up sequentially as well.
The two major choices are either row major (rows are stored one after another) or column major (columns are stored one after another). These either group the linear representation of the array by the row or by the column.
1,1 | 1 | 0x1000 | 1 | |||
1,3 | 13 | 0x1008 | 13 | |||
2,2 | 10,000 | 0x1010 | 10,000 | |||
3,1 | -25 | 0x1018 | -25 | |||
3,3 | 1,024 | 0x1020 | 1,024 |
Ada uses a row-major order.
ALGOL 60 does not specify an order, but many ALGOL 60 compilers use row-major order.
C uses a row-major order.
C++ uses a row-major order.
COBOL uses a row-major order.
FORTRAN explicitly requires a column-major order.
Java uses a row-major order.
Matlab uses a column-major order.
Modula-2 uses a row-major order.
Pascal implicitly requires a row-major order.
PL/I uses a row-major order.
Stanford CS Education Library This [the following section until marked as end of Stanford University items] is document #101, Essential C, in the Stanford CS Education Library. This and other educational materials are available for free at http://cslibrary.stanford.edu/. This article is free to be used, reproduced, excerpted, retransmitted, or sold so long as this notice is clearly reproduced at its beginning. Copyright 1996-2003, Nick Parlante, nick.parlante@cs.stanford.edu.
The following declares a two-dimensional 10 by 10 array of integers and sets the first and last elements to be 13.
int board [10][10];
board[0][0] = 13;
board[9][9] = 13;
The implementation of the array stores all the elements in a single contiguous block of memory. The other possible implementation would be a combination of several distinct one dimensional arrays -- thats not how C does it. In memory, the array is arranged with the elements of the rightmost index next to each other. In other words, board[1][8] comes right before board[1][9] in memory.
(highly optional efficiency point) Its typically efficient to access memory which is near other recently accessed memory. This means that the most efficient way to read through a chunk of the array is to vary the rightmost index the most frequently since that will access elements that are near each other in memory.
Stanford CS Education Library This [the above section] is document #101, Essential C, in the Stanford CS Education Library. This and other educational materials are available for free at http://cslibrary.stanford.edu/. This article is free to be used, reproduced, excerpted, retransmitted, or sold so long as this notice is clearly reproduced at its beginning. Copyright 1996-2003, Nick Parlante, nick.parlante@cs.stanford.edu.
ABSOLUTE VALUE |B. APL monadic function that when applied to a vector returns a matrix with each element having the absolute value of the corresponding element of the source matrix.
ADDITION A+B. APL dyadic function that adds all of the corresponding element of the matrices A and B and places the results into matrix A. If B is a scalar, this fucntion adds the scalar B to every element in matrix A and places the results into matrix A.
AND ∧(x) APL dyadic function that returns the logical AND of two matrices. Form is A∧B. This function can be used with two matrices to logically AND all of the corresponding elements of the two matrices; or with a matrix and a vector or scalar to logically AND the scalar to every element of the matrix with the value of the vector or scalar. Each element of the operation must intiially have the value of one (1) or zero (0). One is TRUE and zero is FALSE.
PostScript aload(x) PosScript array operator that places on the stack all of the elements of an array followed by the array itself.
LISP ARRAY(x) LISP function that takes three or more arguments of type name, type, and dimnsions, and creates an array of that name, type, and dimensions.
PL/I DIM(x, n) Pl/I built-in function that returns the size of an array. The data item x is the name of the array to be examined. The data item n is the number of the dimension of the specififed array for which the extent is to be returned. The function is most efficient if data item n is of type FIXED BINARY (15). It is an error if the array has less than n dimensions or if n is zero or less or if the array x is not currently allocated. For a matrix the value of n should be either 1 or 2.
PL/I LBOUND(x, n) Pl/I built-in function that returns the lower bound for the specififed dimension of an array. The data item x is the name of the array to be examined. The data item n is the number of the dimension of the specififed array for which the extent is to be returned. The function is most efficient if data item n is of type FIXED BINARY (15). It is an error if the array has less than n dimensions or if n is zero or less or if the array x is not currently allocated. For a matrix, the value of n should be 1 or 2.
PL/I HBOUND(x, n) Pl/I built-in function that returns the upper bound for the specififed dimension of an array. The data item x is the name of the array to be examined. The data item n is the number of the dimension of the specififed array for which the extent is to be returned. The function is most efficient if data item n is of type FIXED BINARY (15). It is an error if the array has less than n dimensions or if n is zero or less or if the array x is not currently allocated. For a matrix, the value of n should be 1 or 2.
PL/I SUM(x) Pl/I built-in function that returns the total sum of all of the values of the elements in an arithmetic array x. Note that the IBM PL/I-F compiler converts all array values to floating point to perform the operation and returns a result in floating point. This may create small rounding errors for commercial programmers needing dollar and cents accuracy.
PL/I PROD(x) Pl/I built-in function that returns the total product of all of the values of the elements in an arithmetic array x. The PROD function is always carried out in floating point arithmetic. This may create small rounding errors for commercial programmers needing dollar and cents accuracy.
Ah, variable names.ÊLength is not a virtue in a name; clarity of expression is.ÊA global variable rarely used may deserve a long name, maxphysaddr say.ÊAn array index used on every line of a loop neednt be named any more elaborately than i.Ê Saying index or elementnumber is more to type (or calls upon your text editor) and obscures the details of the computation.ÊWhen the variable names are huge, its harder to see whats going on.ÊThis is partly a typographic issue; consider
for(i=0 to 100)
array[i]=0 ;
vs.
for(elementnumber=0 to 100)
array[elementnumber]=0;
The problem gets worse fast with real examples.ÊIndices are just notation, so treat them as such. Rob Pike, Notes on Programming in C, February 21, 1989
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
return to table of contents
free downloadable college text book
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
previous page | next page |
Tweets by @osdata |
free computer programming text book projectBuilding a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming. If you like the idea of this project, Supporting the entire project: If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church) free downloadable college text book on computer programming. |
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
UNIX used as a generic term unless specifically used as a trademark (such as in the phrase UNIX certified). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.
Names and logos of various OSs are trademarks of their respective owners.
Copyright © 2010, 2011 Milo
Created: December 8, 2010
Last Updated: February 26, 2011
return to table of contents
free downloadable college text book
previous page | next page |