* ======================================================================= * File: matrix 001.SPS . * Date: 24-Oct-2003 . * Author: Bruce Weaver, weaverb@mcmaster.ca . * Notes: Matrix Algebra Basics using SPSS Matrix Language . * ======================================================================= . * Matrix Algebra Basics . * http://www.math.hmc.edu/calculus/tutorials/matrixalgebra/matrixalgebra.pdf . matrix. compute a = {1,-1,3; 1,0,-1; 2,1,6}. compute b = {6,9;-4,-6}. compute c = {1,2;-1,0}. compute sum.bc = b+c. /* Sum of 2 matrices: B + C . compute diff.bc = b-c. /* B - C. compute bx3 = 3*B. /* Scalar times a matrix . compute bc = b*c. /* Matrix multiplication: B*C . compute cb = c*b. /* Matrix multiplication: C*B . compute cinvc = c*inv(c). /* C times inverse of C: C*C^-1. compute invcc = inv(c)*c. /* Inverse of C times C: C^-1*C. print b/title = 'B'. print c/title = 'C'. print t(b)/title = "B' - transpose of B". print sum.bc /title = 'Matrix Addition: B+C'. print diff.bc /title = 'Matrix Subtraction: B-C'. print bx3 /title = 'Scalar x Matrix: 3*B'. print bc /title = 'Matrix Multiplication: B*C'. print cb /title = 'Matrix Multiplication: C*B'. print det(b) /title = 'Determinant of B' . print det(c) /title = 'Determinant of C' . print /title='NOTE: A matrix is only invertible if its determinant is NOT equal to 0.'. print inv(c) /title = 'Inverse of a matrix: C^-1'. print cinvc /title = 'C times inverse of C: C*C^-1'. print invcc /title = 'Inverse of C times C: C^-1*C'. print a /title = 'A (a 3x3 matrix)'. print det(a)/title = 'Determinant of A'. print inv(a)/title = 'Inverse of A: A^-1'. compute y = {0; 0; 1; 1; 3}. /* Y . compute tyy = t(y)*y. /* Transpose of A times A . compute sumsq.y = mssq(y). /* Matrix sum of squares. print /title = '---------------------------------------------------------------'. print Y /title = 'Column matrix Y'. print /title = 'For a column matrix like Y, TRANS(Y)*Y = MSSQ(Y), where MSSQ = matrix SS.'. print tyy /title = 'Transpose of Y times Y'. print sumsq.y /title = 'Matrix sum of squares, MSSQ(Y)'. end matrix. * ======================================================================= .