(*:Summary: This package contains some programs for use in Math 314. *) BeginPackage["ClassPackage`"] (* Usage messages *) SolveForInTermsOf::usage = "Let eqs be a system of equations. Let vars1 and vars2 be lists of variables. Then SolveForInTermsOf[eqs, vars1, vars2] will attempt to express the values of the first set of variables (vars1) in terms of the second set of variables (vars2). Bad things happen if there is no unique solution to this problem."; CoefficientMatrixOfSystem::usage = "Let E be a list of linear equations and let x be the list of variables which appear in E. Let A = CoefficientMatrixOfSystem[E,x] and b = ConstantMatrixOfSystem[E,x]. Then A . x == b is the matrix form of the system E."; ConstantMatrixOfSystem::usage = "Let E be a list of linear equations and let x be the list of variables which appear in E. Let A = CoefficientMatrixOfSystem[E,x] and b = ConstantMatrixOfSystem[E,x]. Then A . x == b is the matrix form of the system E."; CoefficientMatrix::usage = "There is no help available for this command."; ConstantMatrix::usage = "There is no help available for this command."; Begin["`Private`"] SolveFor[eqs_, vars_] := vars /. Solve[eqs, vars][[1]] SolveForInTermsOf[eqs_, vars1_, vars2_] := Block[ {allvars,elimvars,deqs}, allvars = { }; Scan[ (allvars = Join[allvars, {If[Head[#]===Symbol,#]}])&, eqs, Infinity]; elimvars = Complement[ allvars, Union[vars1,vars2,{Null}]]; deqs = Eliminate[eqs, elimvars] /. 0. -> 0; vars1 /. Solve[deqs, vars1][[1]] ] CoefficientMatrix[v_, x_] := Block[ {M,n,i}, M = Collect[v,x]; n = Length[x]; Transpose[Table[Coefficient[ M, x[[i]] ], {i,1,n} ] ] /. 0. -> 0 ] ConstantMatrix[v_, x_] := Block[ {M,n,i,A}, M = Collect[v,x]; n = Length[x]; A = Transpose[Table[Coefficient[ M, x[[i]] ], {i,1,n} ] ]; M - A . x /. 0. -> 0 ] CoefficientMatrixOfSystem[E_, x_] := Block[ {v,M,n,i,a,b}, v = E /. a_ == b_ -> a-b; M = Collect[v,x]; n = Length[x]; Transpose[Table[Coefficient[ M, x[[i]] ], {i,1,n} ] ] ] ConstantMatrixOfSystem[E_, x_] := Block[ {v,M,n,i,A,a,b}, v = E /. a_ == b_ -> a-b; M = Collect[v,x]; n = Length[x]; A = Transpose[Table[Coefficient[ M, x[[i]] ], {i,1,n} ] ]; A . x - M /. Table[x[[i]] -> 0, {i,1,n}] ] End[ ] EndPackage[ ]