|\^/| Maple V Release 4 (Worcester Polytechnic Institute) ._|\| |/|_. Copyright (c) 1981-1996 by Waterloo Maple Inc. All rights \ MAPLE / reserved. Maple and Maple V are registered trademarks of <____ ____> Waterloo Maple Inc. | Type ? for help. # 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. Warning, new definition for norm Warning, new definition for trace [BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, coldim, colspace, colspan, companion, concat, cond, copyinto, crossprod, curl, definite, delcols, delrows, det, diag, diverge, dotprod, eigenvals, eigenvalues, eigenvectors, eigenvects, entermatrix, equal, exponential, extend, ffgausselim, fibonacci, forwardsub, frobenius, gausselim, gaussjord, geneqns, genmatrix, grad, hadamard, hermite, hessian, hilbert, htranspose, ihermite, indexfunc, innerprod, intbasis, inverse, ismith, issimilar, iszero, jacobian, jordan, kernel, laplacian, leastsqrs, linsolve, matadd, matrix, minor, minpoly, mulcol, mulrow, multiply, norm, normalize, nullspace, orthog, permanent, pivot, potential, randmatrix, randvector, rank, ratform, row, rowdim, rowspace, rowspan, rref, scalarmul, singularvals, smith, stack, submatrix, subvector, sumbasis, swapcol, swaprow, sylvester, toeplitz, trace, transpose, vandermonde, vecpotent, vectdim, vector, wronskian] > > 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] > ); [1 -2 0 -5] [ ] M := [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 [1 -2 0] [ ] A := [2 1 1] [ ] [0 3 -2] > > multiply( inverse(A), M); [1 0 0 -1] [ ] [0 1 0 2] [ ] [0 0 1 5] > # So our solution is x = [ -1, 2, 5 ]^T > # Cramer's rule. (Only works if det(A) <> 0.) > print(` Computing the determinant of A:`); Computing the determinant of A: > det(A); -13 > # 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]); [-5 -2 0] [ ] B1 := [ 5 1 1] [ ] [-4 3 -2] > printf(` Determinant of B1 is %g \n`,det(B1)); Determinant of B1 is 13 > > X1 := det(B1)/det(A); X1 := -1 > # Solve for x2 using Cramer's Rule: > B2 := submatrix( M, 1..3, [1,4,3]); [1 -5 0] [ ] B2 := [2 5 1] [ ] [0 -4 -2] > printf(` Determinant of B2 is %g \n`,det(B2)); Determinant of B2 is -26 > > X2 := det(B2)/det(A); X2 := 2 > # Solve for x3 using Cramer's Rule: > B3 := submatrix( M, 1..3, [1,2,4]); [1 -2 -5] [ ] B3 := [2 1 5] [ ] [0 3 -4] > printf(` Determinant of B3 is %g \n`,det(B3)); Determinant of B3 is -65 > > X3 := det(B3)/det(A); X3 := 5 > quit bytes used=1071656, alloc=917336, time=0.04