1 MATALG version 1.40 15 October 1996 MATALG is an interactive matrix algebra program. This help file includes information on the commands MATALG will accept; the operators and functions MATALG allows in a formula; how to install and run MATALG on different computers. 2 Background MATALG was developed by John Burkardt, Mathematics Department, Iowa State University, Ames, Iowa, 50011 and Charles G. Cullen Department of Mathematics and Statistics, University of Pittsburgh, Pittsburgh, Pennsylvania, 15260 The developer's EMAIL addresses are: burkardt@iastate.edu cullen@vms.cis.pitt.edu This program accompanies the textbook Charles G. Cullen, An Introduction to Linear Algebra, Second Edition Harper Collins College Publishers, Glenview, Illinois, 1996 All rights to this program are reserved by the authors, the University of Pittsburgh, and the publishers. MATALG may not be reproduced in any manner without permission. Schools using this textbook are automatically granted permission to distribute copies of MATALG to their faculty and students. Versions are available for the IBM PC, the Apple Macintosh, DEC VAX/VMS computers, and UNIX computers. The VMS and UNIX versions can be requested and sent via EMAIL to burkardt@icam.vt.edu. Precompiled IBM and Macintosh versions are available for the modest fee of $5.00 to cover postage and handling, and may be ordered by EMAIL, or by sending a letter to either author. The FORTRAN source code of the program can be made available to interested users. 2 Acknowledgements Development of this program was partially supported by a courseware development grant from the College of General Studies of the University of Pittsburgh. Some of the software in MATALG has been adapted from routines in the EISPACK and LINPACK libraries. 2 Purpose MATALG can perform most common calculations with real-valued scalars, vectors, and matrices. Complex arithmetic is NOT supported. The possibly complex eigenvalues and eigenvectors of a real matrix may be computed, however, using a special storage format. When using MATALG, the user names the variables, declares their sizes, gives them values, and defines formulas involving them; the program interprets and evaluates those formulas. The program can be used as a simple programming language for carrying out matrix calculations. For example, the following commands declare A to be a 3 by 3 matrix, give it a value, and request the determinant. Then the value of A(3,3) is changed, the determinant is re-evaluated, and the matrix is inverted. Command Purpose ------- ------- E A,3,3 Enter a matrix called "A" which has 3 rows and 3 columns. 1,2,3 The values of A must now be entered. 4 5 6 Values are entered one row at a time, 7, 8, 9 separated by commas or spaces. =DET(A) Compute the determinant of A (which is 0). Because there's nothing on the left hand side of the = sign, we are stating that we want to compute, but not save, the result. A(3,3)=0 Change A(3,3) to 0. =DET(A) Compute the determinant of A again. This time, it's 27. B = INV(A) Compute the inverse of A, and call it B. = A*B Compute A*B to see if it is really the identity matrix. Don't bother saving the result. The program will print out prompts, ask for missing input, help you decide what to do next, and show the intermediate results as you go along. These messages were not included in the example above. Formulas can be more complicated, involving several functions. In order to compute the eigenvalues of transpose(A)*A in the above example, for instance, you could type the single line =EVAL(TRANS(A)*A) 2 Commands A command to MATALG is usually a single letter. Most commands must be followed by "arguments", which tell MATALG what object it is to operate on, how large it is, and so forth. If a command has arguments, these are including in the list, with symbolic names. Command and arguments Short definition --------------------- ---------------- D filename Open a transcript file. E name, rows, cols, values Enter variable. I Initialize. K name Kill variable(s). L name, lo, hi, nstep Tabulate formula. M LU/QR/SVD, name Matrix factors. P name Characteristic polynomial. Q Quit. R nstep Repeated evaluation (x=f(x)). S name Save formula value. T name/ALL/blank Type variable. U name Partition a matrix. V Re-evaluate formula W filename, name Write variable to file. X filename Read variable from file. # Begin a comment. $, % Turn paging on or off. < file Get input from file. ? Extensive help. variable = formula Set variable to value of formula. For instance, the entry E name, row, col, values means that when you issue the "E" command, you will also be required to specify: the name of the variable to be entered, the number of rows in the variable, the number of columns in the variable, the value to be assigned to that entry. So a "real" ENTER command, to declare an array "Stanley" containing two rows and three columns of data, might look like: E Stanley 2, 3 1.1 2.4 3.7 4 4.3 9 Here, we have separated the arguments by spaces and extra blank lines. We could just as easily have typed: E Stanley 2, 3 1.1, 2.4, 3.7 4, 4.3, 9 In the listing above, if the arguments of a command are separated by slashes, you have a choice of which one to choose. If the argument is in capital letters, it doesn't represent the name of something, then you should type exactly those letters. So for instance to get the LU factorization of a matrix named "DAVE", you could type: M LU DAVE MATALG doesn't notice whether you type capital letters or not, so you could also type this command as m lu dave or m LU Dave The program will prompt you for the next argument it needs if you don't supply it. Thus, E A 2, 2 is the concise way to enter a matrix named A which has 2 rows and 2 columns. But if you just type E the program will ask you for the name of the variable, and then the number of rows and columns. You can give as much of this information at a time as you like. Variable names may be up to 10 characters long, and may only consist of letters and numbers. The first character of a variable name should be a letter, not a number. You should not try to use a variable name like "SQRT" or "COS" that MATALG has already permanently assigned a meaning to. The values of all variables are stored as real numbers inside the program, and the usual roundoff problems can occur. When you are entering a number into the program, you may use a variety of forms, including integer, rational, decimal and scientific forms: 2 (an integer) 7/4 (a rational value, equals 1.75) 17.23 (a decimal value) 1.5E+2 (a scientific form. "E+2" means multiply by 10**2, so the result equals 150.) 3 Disk file transcript D (filename) The "D" command requests that a disk file be opened with the given name, in which a transcript of the session will be stored. A second "D" command (with no argument) will close the file. The command D B:RECORD.DAT would store the information in the file "RECORD.DAT" on the disk in drive B (or on the Macintosh disk named B). D RECORD.DAT would store the information in the file "RECORD.DAT". File names may be up to 80 characters long and may include device and directory information. 3 Enter a variable E (variable, rows, columns) The "E" command sets up a variable of the given name and size. You should use this command first, to set up variables, before using them in a formula. In some cases, where MATALG can figure out the dimensions of a variable, you can skip the "E" command. For instance, you can type "X=1" and MATALG will realize that X is a scalar. This is called an "implicit declaration". The number of rows and columns must be no more than 12. The program will immediately request that you set the value of the variable. If the variable is a scalar (1 row and 1 column), then its value may be included on the same line. E SQUARE 5,4 would declare a matrix named SQUARE of five rows and four columns. The program will now ask you for 20 values to enter into SQUARE. Similarly, the command E FRED 1,1, 17 would declare a scalar named FRED whose value was 17. Because FRED is a scalar, you may also enter it by typing FRED=17 When you have completed the "E" command, MATALG will print out the variable name and its values so that you may check it. MATALG only uses real valued variables. You cannot assign complex values to any MATALG variable. 3 Help H The "H" command requests a list of all the commands, with one line explanations. 3 Initialize I This command initializes or reinitializes the program. It clears out a fixed amount of workspace to be used by the program. This is done automatically when the program begins, but it may be necessary to issue this command during program execution if all workspace has been used up. WARNING: the "I" command erases the definitions and values of all user variables; to delete only part of the data, use the "K" command instead. Because the "I" command can be "deadly", the program will ask you to confirm that you want to wipe out all the work you've done so far. 3 Kill a variable K (variable) MATALG has a finite amount of space to store variables. To clear all the space used so far, the "I" command will do. But the "I" command destroys ALL user variables and formulas. The "K" command can be used to delete just some variables. It will "undefine" the variable named, and return the space that was used for it. K X will kill the variable named X and return the memory allocated to X to the free space. 3 List a table of values L (Variable, starting value, stopping value, number of steps) This command allows you to list the successive values of a formula for equally spaced values of one of its arguments. The most recent formula you entered is the one that will be tabulated. For example, the commands =DET(X-A) L X, 0.0, 10, 100 will list the value of the characteristic polynomial of A for every tenth of a unit from 0 to 10. 3 Matrix factorization M (LU/QR/SVD, variable name) This command allows you to carry out either the LU, QR or SVD factorization of a rectangular matrix. Type "LU", "QR" or "SVD" and give the name of the matrix to be factored. M LU A would carry out the LU factorization of the matrix A. The LU factorization of an M by N matrix A returns an M by M unit lower triangular matrix L, an M by M permutation matrix P, and an M by N upper triangular matrix U, such that P * A = L * U which is the same as saying A = Transpose(P) * L * U This factorization is useful in solving linear systems with multiple right hand sides. M QR B would carry out the QR factorization of the matrix B. The QR factorization of an M by N matrix A returns an M by M orthogonal matrix Q, and an M by N upper triangular matrix R, such that A = Q * R. This factorization is useful in solving overdetermined systems in the least squares sense and is the essential ingredient in the best algorithms for finding the eigenvalues of a matrix. M SVD C would carry out the singular value decomposition of the matrix C. The SVD of a matrix is a factorization of an M by N matrix A into the factors A = U * S * Transpose(V) where U is an M by N matrix, and S and V are N by N matrices. U and V are orthogonal matrices, and S is diagonal. The nonzero diagonal entries of S are called the "singular values" of A. Once a factorization is carried out, you will be asked if you want to save the factors in variables. If so, you must provide names of variables in which to store L, U and P, or Q and R, or U, S and V. 3 Polynomial P (Variable) If the variable is a square matrix (of order N), this command computes the characteristic polynomial of the matrix. The result is a list of N+1 coefficients. The program will offer to store this information in a variable if you like. You can evaluate the polynomial using formulas involving the "POLY" function. Thus, if A is a matrix, the command P A produces the coefficients of the characteristic polynomial of A. If we store these coefficients in a vector, say PCOEF, then the command =POLY(PCOEF,A) would evaluate the polynomial with the matrix A as its argument. In exact arithmetic, the result should be the zero matrix. If the variable is a vector, then it is assumed that the N roots of an N degree polynomial have been stored in the vector. The command computes the N+1 coefficients of the corresponding polynomial. The commands E V 3 1 1, 2, 3 P V would result in the computation of the coefficients of the polynomial (X-1)*(X-2)*(X-3), which equals X*X*X - 6*X*X + 11*X - 6. In this case, you will be asked to type the name of a vector in which to save the array of coefficients, or RETURN if you don't care to save the coefficients. The vector should be one entry longer than V itself. In this case, if you save the coefficients in a vector W, say, then W will contain the entries: (1, -6, 11, -6) 3 Quit Q Quit. This stops the program. Just in case you did not mean to quit, the program requires that you affirm your decision by asking you to enter "YES" to quit. 3 Repeated evaluation R (steps) Repeated evaluation. This formula only makes sense if you have typed in a formula of the form X=F(X). Here, we understand this equation to mean "Take the current value of X, evaluate F(X), and update X to have that value." For instance, a simple use would be: X=(A*X)/NORM2(A*X) R 15 where A is a matrix and X a vector, represents the power method for finding the dominant eigenvalue of A. 3 Save a variable S (Variable) If a formula is not of the form "variable=expression", the value returned by the formula is not going to be saved. If you decide you want to save the value, the "S" command will do it. =SQRT(16) S X will save the value 4 in X, and is essentially the same as X=SQRT(16) 3 Type a variable T (Variable or 'All' or blank) Requests that the program print the value of one or more variables. T X prints out the value of the variable X. T ALL requests that all the symbols used by the program be displayed. T DEBUG prints out all sorts of stuff, primarily for debugging. T requests that all user variables (but not the program variables) be printed. 3 Partition a matrix U (Variable) Partition a matrix. This command lets you construct new matrices by partitioning an existing matrix. You will be asked: The rows to keep, followed by a zero. The columns to keep, followed by a zero. The name of a matrix in which to store the result, or RETURN if you don't want to save it. You actually define 4 new matrices by this process, and you can see and save the other three if you want. The second matrix is made by deleting the rows you listed, keeping the columns you deleted. The third and fourth matrices are made similarly. The program will let you know that you can examine them. For example, if A is the matrix (11 12 13) (21 22 23) (31 32 33) Then if your row list is 1,0 and your column list is 1,3,0, the (first) submatrix will be (11 13) and the others will be (21 23) (22) (12) (31 33) (32) 3 Value of a formula V Evaluate the current formula (presumably with a new value for at least one of the variables). For example, the sequence of commands E X, 1,1, 2 =X*3 C X, 1,1, 3 V will cause a value of 6 on the first evaluation, and a value of 9 on the second. This command can be used in place of the "R" command if you wish to monitor the calculation closely, perhaps to determine convergence. 3 Write example to file W (Filename, variable) Writes the value of a variable into a file, which may later be read in by this program, or by MATMAN. You are allowed to specify a label for the variable that you write to the file, such as "Singular matrix" or "1993 Tax Data". 3 Read example from file X (Filename) Requests that the given file be opened, and the names of the variables stored there be listed. Presumably, the file was made by this program with the "W" command, or by MATMAN. Once the program has listed the variables, you may pick one to read in. The file "MATALG.DAT" contains some examples you can use. 3 # Comments # comment MATALG assumes that what you type is a command. But you may also wish to simply write a comment or two, to annotate your work, especially if you are making a file transcript. You can do this easily by simply beginning a comment line with a pound sign. For instance, I could give MATALG the following input: # # I'm going to set up the identity matrix. # b = id(3) # # And now, I want to # compute its eigenvalues... # =eval(b) 3 Stop paging ($) MATALG assumes that you are using the program interactively on a terminal which can display 24 lines of text at a time. MATALG therefore is careful, when printing more than 22 lines of text at a time, to pause after every 22 lines, so that you can read that portion of the output. MATALG waits for you to hit RETURN before it will print the rest of the output. You may not want this feature, if you are able to "scroll" on your terminal, or have a larger screen window, or can read fast. You definitely do not want paging if you are not running MATALG interactively, but rather have prepared an input script of some sort. Otherwise, you would have to insert blank lines all through the script, in a fairly unpredictable way. 3 Start paging (%) If you have turned off paging with the $ command, you can restore it at any time by using the % command. 3 Input from file (<) < file Although MATALG is designed for interactive use, you can prepare your commands beforehand in a file, named, for instance, "matalg.inp" and have MATALG process them. On a computer running UNIX or DOS, this would be easily done via the command: matalg < matman.inp However, it's not easy to do on VMS or on a Macintosh. Your alternative is to begin the program interactively, and then tell the program to get the rest of its input from the file. If the file does not end with commands that cause MATALG to quit, then MATALG will return control to you and you are free to type more commands or stop the program. If "paging" is on when you specify an input file, MATALG will automatically turn it off. If any error occurs while the input file is read, MATALG will close the input file, and expect further input from you. 3 Extensive help (?) ? While running the program, you always have the option of the "H" command for quick help. Sometimes, though, that isn't enough. If you really want to see some detailed explanation of a particular command, you can use "?" instead of "H". This causes the program to read the help file "MATALG.HLP" and to display the main topics. At this point your options are: Type a topic, or enough of the topic to be unique. In this case you will get information on the given topic, plus possibly a list of subtopics. Hit the RETURN key. This will back you up one 'level'. If you've just entered the help program, you will back up into the main program. If you're down one subtopic, you'll back up to the topic, and so on. Type "?" to have the information about the current topic repeated. You might give this command several times in a row, just to browse through the same information over and over again. But you might also issue it when backing up, because when backing up to a higher topic, that topic's information is not printed out again unless you specially request it with the "?". 3 Formula evaluation Variable = Formula Requests that the formula be interpreted and evaluated. Formulas such as =1+2 need no variables, but a formula such as =X+Y requires that you have declared the variables X and Y earlier. =A*B+A**2+INV(TRANS(A)*A) is a more complicated example of formula input. Because nothing appears on the left hand side, the formula is evaluated, the value is printed, but nothing is done with the value. (If you decided you did want to save the value computed by this formula, you could use the "S" command). You can, if you like, assign the value of the formula to a variable. Thus you can say =1+2 in which case the result will be printed, or A=1+2 in which case the result will be printed, but also stored in A. So the following are all legal commands: A=2 X=4+SIN(Y) =X+Y The program expects the formula to be in standard FORTRAN and will reject incompatible matrix operations. Assignments may only be made in "scalar" mode. If A and B are matrices, you can't write "A=B" and expect the program to do the right thing. 2 Operators MATALG recognizes formulas involving the following operators: + - * / ** ^ = \ *, which is used in a formula like A*B is standard scalar or matrix multiplication if both arguments are scalars or both are matrices. If one argument is a scalar, then each entry of the other argument will be multiplied by the scalar. If both arguments are row or column vectors, the dot product is taken, resulting in a scalar value. A row times a column vector yields a scalar (inner product). A column times a row vector yields a matrix (outer product). / is standard scalar division. It is used in a formula like X/Y or (A*B)/(X+1) Normally, X would be a scalar quantity. However, as NONSTANDARD shorthand, you may 'divide' a matrix by a scalar, in which case each entry of the matrix is divided by the scalar, e.g. A/2 = (1/2)*A. MATALG will NOT allow you to use the "/" operator to represent multiplication by an inverse matrix. Thus, if A is a matrix, the statement B/A is illegal. However, the statement INV(A)*B will compute the inverse of A and multiply by B, and the statement A \ B will compute the LU factorization of A, and use that to compute the inverse of A times B. + and - may be used for scalars, vectors, or matrices of the same order, in formulas like: A = B+C Also, a NONSTANDARD shorthand allows you to add a scalar to a matrix. In this case, the scalar is added only to the diagonal. Thus, if B is a square matrix, B+2 is a legal formula, which is equivalent to the MATALG formula B+2*ID(N) where "N" is the order of B. ** or ^ (scalar exponentiation) are legal for scalar base and power, such as 2**3 or X**2 or A**B or for a square matrix base and positive or negative integer power, such as A**2 or A^4 or A^(-3). = is used to assign values. For vectors or matrices, this may also be used to assign or change a single entry, as in A(3,2)=7. \ essentially means multiplication by the inverse matrix. In particular, "A\B" will return the solution "x" of A*x=b. However, "A\B" is computed by getting the LU factorization of A and using B as the right hand side of a linear system. This may be more accurate than computing the inverse of A and multiplying that by B. B may be a vector, or an array of several columns. 2 Functions MATALG recognizes and can evaluate many functions. Most functions have the form NAME(ARGUMENT) or NAME(ARGUMENT1,ARGUMENT2) For instance, ABS(X) returns the absolute value of X, and MAX(A,B) returns the maximum of A and B. A few "functions" are actually constants. In particular, PI and EPS are predefined numbers that you may use in formulas. Some of these functions only make sense for scalar quantities, or only for scalars or square matrices. In the following list, each function is listed along with its symbolic arguments. The symbol used for the argument explains what restrictions apply to it. S, S1, S2 : Arguments may ONLY be scalar. V : Arguments may only be a scalar or vector. M : Arguments may be scalar or square matrix. MV : Arguments may be scalar, vector, or square matrix. * : Arguments may be scalar, vector or matrix. I, J : Arguments may only be a positive integer. ABS(*) Absolute value of *. ACOS(S) The arc cosine of S. -1 <= S <= 1. ASIN(S) The arc sine of S. -1 <= S <= 1 ATAN(S) The arc tangent of S. ATAN2(S1,S2) Arc tangent of (S1/S2). Correctly computes ATAN2(1.0,0.0)=PI/2. COS(S) The cosine of S, with S measured in radians. COSD(S) The cosine of S, with S measured in degrees. COSH(S) Hyperbolic cosine of S. DET(M) Determinant of square matrix M. DIAG(*) The diagonal entries of *, stored in a vector. E The base of the natural logarithm system. E=2.71828... You may not change the value of E. EPS The machine epsilon, or unit roundoff number. EPS is the power of 2 such that 1 < 1+EPS and 1=1+(EPS/2) You may not change the value of EPS. EVAL(M) Real and imaginary parts of eigenvalues of matrix M, stored in a matrix of N rows and 2 columns, with the real parts in column 1, and the imaginary parts in column 2. EVEC(M) Eigenvectors of matrix, stored in square matrix of same size as M. (Eigenvectors corresponding to a complex pair: If eigenvalues j and j+1 are a complex pair, then the eigenvector for eigenvalue j is column j + i*column j+1, and the eigenvector for eigenvalue j+1 is column j - i*column j+1.) EXP(S) Exponential of S. GCF(I,J) Greatest common factor of two integers. HILBERT(I) The Hilbert matrix of order I. HILBINV(I) The inverse of the Hilbert matrix of order I. HOUSE(V) The Householder elementary reflector matrix H, defined as H = I - 2*(V * TRANSPOSE(V)) / (TRANS(V)*V) ID(I) The matrix identity of order I. ID(3) is the 3 by 3 identity matrix, for instance. INT(*) Truncate real values to their integer part. INT(1.0) = INT(1.1) = INT(1.9) = 1. INV(M) The inverse matrix of the square matrix M. If M is singular, there will be no inverse. IVAL(M) Imaginary parts of eigenvalues of matrix M, stored in a column vector. KRYLOV(M,V,I) Returns a rectangular matrix whose columns are a sequence of I Krylov vectors: V, M*V, M*M*V, ..., M**(I-1)*V. LCM(I,J) Least common multiple of two integers. LN(S) Natural logarithm of S. S must be greater than 0. LOG(S) Natural logarithm of S. S must be greater than 0. LOG10(S) Logarithm base 10 of S. S must be greater than 0. LOG2(S) Logarithm base 2 of S. S must be greater than 0. MAX(S1,S2) Maximum of S1 and S2. MIN(S1,S2) Minimum of S1 and S2. NEG(*) Changes sign of *. NINT(*) Nearest integer value to entries of *. NORM0(*) Maximum or infinity norm of a vector or matrix. NORM0(S) = ABS(S) NORM0(V) returns the maximum of the absolute values of the entries of V. NORM0(M) returns the maximum of the sum of the absolute values of the entries in each row. NORM1(*) The L1-norm of a vector or matrix. NORM1(S) = ABS(S). NORM1(V) returns the sum of the absolute values of the entries of V. NORM0(M) returns the maximum of the sum of the absolute values of the entries in each column. NORM2(MV) L2-norm, Euclidean norm or root-mean-square norm of a vector or a square matrix M. NORM2(V) returns the square root of the sum of the squares of the entries of V. NORM2(M) returns the maximum magnitude of the eigenvalues of Transpose(M)*M. NORME(*) The EISPACK norm. NORME(M) returns the sum of the absolute values of all the entries of a matrix M. NORME may also be applied to a vector, giving the same results as NORM1(V). NORMF(*) The Frobenius norm. NORMF(M) returns the square root of the sum of the squares of all the entries of a matrix M. NORMF may also be applied to a vector, giving the same results as NORM2(V). NORMS(MV) The spectral "norm". NORMS(M) returns the value of the maximum of the absolute values of all the eigenvalues of the matrix M. Note that the spectral norm is NOT a true norm, although it is frequently used as though it were. PI 3.14159265358979... You may not change the value of PI. POLY(V,M) Polynomial evaluation. V should contain the coefficients of the polynomial, with V(1) the coefficient of the highest order, and the last entry of V being the constant term. M is the scalar or square matrix argument of the polynomial. RAN(*) Fills * with random numbers between 0 and 1. RCOND(M) RCOND(M) is the estimate of the reciprocal condition number of the matrix M, as computed by the LINPACK routine SGECO. The condition number of a matrix M is defined as COND(M) = NORM(M) * NORM(INVERSE(M)) RCOND assumes that the L-1 norm is used to define COND(M), and then RCOND(M) is defined by RCOND(M) = 1 / COND(M). If the matrix M is singular, then the condition number is infinite, and RCOND will be zero. ROUND(*) Replaces all "small" entries of * by 0. Here "small" means less than RTOL in absolute value. RTOL The tolerance used for the ROUND command, initially set to EPS. To change the value of RTOL, simply reassign it with a statement like "RTOL=0.1E-6". RVAL(M) Real parts of eigenvalues of matrix, stored in a column vector. SEED The current seed used for the random number generator. SEED always has a positive integer value. SEED is initialized to 123456789. Each time you call RAN, SEED is changed to a new integer value that exactly records the next random number to be generated. You can change the value of SEED, using a command like "SEED=14537". Note that SEED should be set to a positive integer value. One reason to set the value of SEED is that you can control how the RAN function works. If you note the value of SEED, then generate a sequence of random values, and then reset the value of SEED to the value you noted, you can regenerate the exact same sequence. SIN(S) The sine of S, with S measured in radians. SIND(S) The sine of S, with S measured in degrees. SINH(S) Hyperbolic sine of S. SQRT(S) Square root of S. S must be non-negative. STEP(S) Heavyside step function. STEP=0 if S < 0, STEP=1 if 0 <= S. TAN(S) Tangent of S. TAND(S) Tangent of S, measured in degrees. TANH(S) Hyperbolic tangent of S. TRACE(*) Sum of diagonal elements of *. TRANS(*) Transpose of matrix or vector. A=TRANS(A) is a legal formula if A is square. ZERO(I) Matrix zero of order I. ZERO(4) is the 4 by 4 zero matrix. I! Factorial of I. I should be an integer from 0 to 25. 0!=1, 1!=1, 2!=1*2=2, 3!=1*2*3=6, and so on. For large I, the exact value is not returned. 2 DOS PC version The PC disk containing MATALG does NOT include a system file, so you will need to boot up your PC before starting MATALG. Insert the MATALG disk, and type "MATALG". If your PC has several floppy drives, or you are working in another directory, you may have to specify the drive in which the disk was inserted, as in "B:MATALG". If your PC has a hard disk, you may copy the files MATALG.EXE MATALG.HLP MATALG.DAT to the hard disk, to make running the program more convenient. If the program seems to be in an infinite loop, or needs to be terminated immediately, typing CTRL-C should kill it. 3 Redirecting input and output on a DOS PC Although the program is designed for interactive use, the user may prepare a set of input commands, store them in a file, and "feed" them to the program using the standard DOS redirection symbol "<". If the input file were called "mywords", then the execution statement would be: matalg < mywords Similarly, although MATALG has a built in capability of saving in a file a copy of everything that appeared on the screen, you may instead choose to use the DOS redirection symbol ">" to store the output in a file. In this case, you will surely also want to have prepared the input in advance, since you will see no prompts on the screen, so the execution command might look like: matalg < mywords > output If you are going to "feed" an input file to MATALG, you should turn off paging by issuing the "$" command as the first command in the file. Normally, MATALG will pause after 22 lines of output, and ask you to hit RETURN before it will proceed. Typing "$" tells MATALG not to do that. If you leave MATALG in "paging" mode, then it will be almost impossible to properly set up an input file, since you will have to anticipate where to insert extra blank lines that signify hitting RETURN. 3 DOS PC compilation details The program was compiled on a Gateway 2000 PC with the Microsoft Windows 3.1 operating system. The compilation used Microsoft FORTRAN version 5.1. The source code file was broken up into separate files because the original file was too large. The files were named "MATALG1.FOR" through "MATALG6.FOR". The first file contained the main program, and the remaining files contained the subroutines and functions, alphabetically, as follows: MATALG1.FOR Main program MATALG2.FOR A*.F through C*.F MATALG3.FOR E*.F through G*.F MATALG4.FOR H*.F through N*.F MATALG5.FOR P*.F through R*.F MATALG6.FOR S*.F through W*.F The compilation statements were: FL /FPi /c MATALG1.FOR FL /FPi /c MATALG2.FOR FL /FPi /c MATALG3.FOR FL /FPi /c MATALG4.FOR FL /FPi /c MATALG5.FOR FL /FPi /c MATALG6.FOR The compilation switch "/FPi" was used, so that the program would run correctly whether or not a machine had an 8087 math coprocessor chip. If the machine has a math coprocessor chip, the program will exploit it. The LINK statement, which created the executable, was LINK MATALG1+MATALG2+MATALG3+MATALG4+MATALG5+MATALG6 The library used was LLIBFOR7.LIB. 2 Macintosh version The Macintosh disk containing MATALG does NOT include a system file, so you will need to boot up your Macintosh before starting MATALG. Insert the disk containing MATALG. Move the mouse to the MATALG disk and quickly click it twice. This will "open" the disk, displaying all of the files in it. Move the mouse to the 'MATALG' icon and quickly click twice to begin the program. If your Macintosh has a hard disk, you may copy the files MATALG MATALG.HLP MATALG.DAT to the hard disk, to make running the program more convenient. If the program seems to be in an infinite loop, or needs to be terminated immediately, typing COMMAND-., that is, "Cloverleaf-Period", should kill it. 3 Mac compilation details The 68K version of MATALG was compiled on an Apple Macintosh II computer, running System 7.5, using Absoft Mac FORTRAN II version 3.4. The PowerPC version of MATALG was compiled on an Apple PowerPC, running System 7.5, using Absoft FORTRAN version 4.1. The latest versions of the Absoft compiler have several useful features: * The "-N9" compiler option, which causes the the program to check every half-second to see whether the COMMAND-period keys have been pushed, signaling that the user wishes to abort the program. * The "-N13" compiler option, which corrects a problem in which the program was running out of stack memory, resulting in no output appearing on the screen. * The "-mrwe" switch, which causes the program output to appear in a more manageable window, with user control over the fonts and font sizes. * The ability to cut and paste inside the command window. 2 UNIX version Anyone who wants a UNIX version of MATALG will be given a copy of the source code to install. On UNIX, if you're working in the same directory in which the executable program is stored, the program can be run simply by typing: matalg However, if the program is in another directory, you may need to give the full directory name of the executable file, as in: /usr/users/burkardt/bin/matalg If MATALG has been installed by an instructor for use by students from other accounts, then the instruct must "unprotect" the executable program, the help file, and the data file, so that UNIX will allow the students to access them. The commands required would be something like this: chmod +x matalg chmod +r matalg.hlp chmod +r matalg.dat If the program seems to be in an infinite loop, or needs to be terminated immediately, typing CTRL-C should kill it. 3 UNIX Compilation details The UNIX version of MATALG has been compiled and run on a DEC ALPHA running DEC OSF/1, a Silicon Graphics IRIS workstation, a Sun SPARCstation. For the ALPHA, IRIS and SPARCstation, the command to compile and link was simply: f77 matalg.f mv a.out matalg 3 Redirecting input and output on UNIX Although the program is designed for interactive use, the user may prepare a set of input commands, store them in a file, and "feed" them to the program using the standard UNIX redirection symbol "<". If the input file were called "mywords", then the execution statement would be: matalg < mywords Similarly, although MATALG has a built in capability of saving in a file a copy of everything that appeared on the screen, you may instead choose to use the UNIX redirection symbol ">" to store the output in a file. In this case, you will surely also want to have prepared the input in advance, since you will see no prompts on the screen, so the execution command might look like: matalg < mywords > output If you are going to "feed" an input file to MATALG, you should turn off paging by issuing the "$" command as the first command in the file. Normally, MATALG will pause after 22 lines of output, and ask you to hit RETURN before it will proceed. Typing "$" tells MATALG not to do that. If you leave MATALG in "paging" mode, then it will be almost impossible to properly set up an input file, since you will have to anticipate where to insert extra blank lines that signify hitting RETURN. 2 VMS version Anyone who wants a VMS version of MATALG will be given a copy of the source code to install. On VMS, if you're working in the same directory in which the executable program is stored, the program can be run simply by typing: RUN MATALG On VMS, it is also possible for a single copy of MATALG to be installed by an instructor, and then used by students from other accounts. In that case, the instructor must "unprotect" the executable program, the help file and the data file, so that VMS will allow the students to access them. The commands required would be something like this: SET PROTECT=(W:RE) MATALG.EXE SET PROTECT=(W:R) MATALG.HLP SET PROTECT=(W:R) MATALG.DAT Then the instructor must tell the students the location of the directory where the files are kept, which might be USR$ROOT:[INSTRUCTOR.PROGRAMS] The students can then run the program by typing a command like RUN USR$ROOT:[INSTRUCTOR.PROGRAMS]MATALG If the program seems to be in an infinite loop, or needs to be terminated immediately, typing CTRL-Y should kill it. 3 VMS bugs and problems If MATALG is to be made available to a class, the source code should be modified by changing the OPEN statement for the help file to include the VMS specific keywords: "SHARED,READONLY" This allows other users to examine the help file, but with read privileges only. 3 VMS Compilation details This program was compiled on a VAX/VMS system using the DEC FORTRAN compiler. The commands used to compile and load the program were: FORTRAN/NOLIST MATALG.FOR LINK/NOMAP MATALG.OBJ 3 Redirecting input and output on VMS Although the program is designed for interactive use, the user may prepare a set of input commands, store them in a file, and "feed" them to the program using the VMS ASSIGN command to tell the program where to look. If the input file were called "MYWORDS.DAT", then the execution statements would be: ASSIGN/USER MYWORDS.DAT SYS$INPUT RUN MATALG Similarly, although MATALG has a built in capability of saving in a file a copy of everything that appeared on the screen, you may instead choose to use the ASSIGN command to store the output in a file. In this case, you will surely also want to have prepared the input in advance, since you will see no prompts on the screen, so the execution command might look like: ASSIGN/USER MYWORDS.DAT SYS$INPUT ASSIGN/USER OUTPUT.DAT SYS$OUTPUT RUN MATALG If you are going to "feed" an input file to MATALG, you should turn off paging by issuing the "$" command as the first command in the file. Normally, MATALG will pause after 22 lines of output, and ask you to hit RETURN before it will proceed. Typing "$" tells MATALG not to do that. If you leave MATALG in "paging" mode, then it will be almost impossible to properly set up an input file, since you will have to anticipate where to insert extra blank lines that signify hitting RETURN. 2 Double precision version The standard version of MATALG uses single precision, in which a typical variable is declared to be REAL, and is allocated a single computer word of storage, which is typically 32 bits. If you are making calculations where you want extra accuracy, or if you are using poorly conditioned matrices, you may want to try to make a double precision version of MATALG, in order to get better results. There is a publicly accessible tool for doing this, called "S2D". If you have access to the Internet, you can find the source code for this program in NETLIB. Send the message "send index from fortran" to the address "netlib@research.att.com" for details. Otherwise, you will have to make the conversion by hand. In that case, there are a number of things you must take care of. 1) Reset the variable EPS, which records the machine accuracy. In subroutine INICOM, change the line eps=2.0**(-23) to eps=2.0**(-52) 2) Change the REAL function to DBLE. There are several lines of code where an INTEGER quantity is converted to a REAL quantity using the REAL function, as in: TEMP = 1.0 / REAL (N) The REAL function in these lines should be replaced by DBLE: TEMP = 1.0 / DBLE (N) 3) Change the declarations of most of the variables. Almost all of the variables which are declared REAL should be declared "DOUBLE PRECISION" instead. 4) In subroutine HELLO, change the line output='This version uses real arithmetic." to output='This version uses double precision arithmetic.'