# # Numerical Mathematics and Computing, Fifth Edition # Ward Cheney & David Kincaid # Brooks/Cole Publ. Co. # (c) 2003 # # file: gauss_elim1 # # Solving linear systems # # Using package linalg # with(linalg): A := array([[ 6, -2, 2, 4], [12, -8, 6, 10], [ 3, -13, 9, 3], [-6, 4, 1, -18]]); b := array( [16, 26, -19, -34]); linsolve(A,b); # # Using package LinearAlgebra # with(LinearAlgebra): A := Matrix([ [6,-2,2,4],[12,-8,6,10], [3,-13,9,3],[-6,4,1,-18]]); b := Vector([16,26,-19,-34]); x := LinearSolve(A, b); with(LinearAlgebra): Eqns := [ 6*x1 -2*x2 + 2*x3 + 4*x4 = 16, 12*x1 -8*x2 + 6*x3 + 10*x4 = 26, 3*x1 -13*x2 + 9*x3 + 3*x4 = -19, -6*x1 +4*x2 + x3 - 18*x4 = -34]; Vars := [x1, x2, x3, x4]; Ab := GenerateMatrix(Eqns, Vars, augmented=true); LinearSolve(Ab, method=solve);