# January 18, 2002. Dr. W. J. Martin # Sample MAPLE input file. Matrix computations. # # GOAL: Solve the linear system # x1 - 2x2 = -5 # 2x1 + x2 + x3 = 5 # 3x2 - 2x3 = -4 # using Cramer's Rule and directly. # # with(linalg); # Load MAPLE's suite of linear algebra routines. M := matrix (3,4, # Matrix M has 3 rows, 4 columns. Here are teh entries: [ 1, -2, 0, -5, 2, 1, 1, 5, 0, 3, -2, -4] ); # Obtain the coefficient matrix: A := submatrix( M, 1..3, 1..3); # Select first, second, third column of M multiply( inverse(A), M); # So our solution is x = [ -1, 2, 5 ]^T # Cramer's rule. (Only works if det(A) <> 0.) print(` Computing the determinant of A:`); det(A); # In Cramer's rule, to find xi: # (1) replace the i-th column of A by the RHS # vector b = [ -5, 5, -4 ]^T, # (2) compute the determinant of this matrix, # (3) divide this answer by det(A) to find xi. # Solve for x1 using Cramer's Rule: B1 := submatrix( M, 1..3, [4,2,3]); printf(` Determinant of B1 is %g \n`,det(B1)); X1 := det(B1)/det(A); # Solve for x2 using Cramer's Rule: B2 := submatrix( M, 1..3, [1,4,3]); printf(` Determinant of B2 is %g \n`,det(B2)); X2 := det(B2)/det(A); # Solve for x3 using Cramer's Rule: B3 := submatrix( M, 1..3, [1,2,4]); printf(` Determinant of B3 is %g \n`,det(B3)); X3 := det(B3)/det(A); quit