(*Example 1.27, page 23*)
d={{1,2,1},{3,1,-2},{4,-3,-1}};
Print["D is ",d//MatrixForm];
Print[" RREF[D] is ",RowReduce[d]//MatrixForm];

(*Example 1.29, page 26*)
A={{1,2,1},{3,1,-2},{4,-3,-1}};
H={2,1,1};
Print["A is ",A//MatrixForm];
Print["H is ",H//MatrixForm];

Print[" RREF[ A ] is ",RowReduce[A]//MatrixForm];
Print["Rank[A]=",MatrixRank[A] ];
Print[" Rank of [A] is the number of lines with non-zero entry in RREF[ A ] = 3 "];

aug={{1,2,1,2},{3,1,-2,1},{4,-3,-1,1}};
Print["Augmented matrix [A | H] is ",aug//MatrixForm ];
Print[" RREF[ A | H  ] is ",RowReduce[aug]//MatrixForm];

Print[" Rank of [A|H] is the number of lines with non-zero entry in RREF[ A | H  ] = 3 "];
Print["Rank[A|H]= ",MatrixRank[aug]];

Print["Solution, {x1,x2,x3}=",LinearSolve[A,H]];
Print["Rank of [A|H] and that of A are the same, hence there is solution"];

(* complementary example to Example 1.30, page 27*)
A={{0,1,2},{0,1,0},{0,0,1}};
H={-1,-1,-1};
Print["A is ",A//MatrixForm];

Print[" RREF[ A ] is ",RowReduce[A]//MatrixForm];
Print["Rank[A]=",MatrixRank[A] ];
Print[" Rank of [A] is the number of lines with non-zero entry in RREF[ A ] = 2 "];

Print["H is ",H//MatrixForm];
aug={{1,2,1,2},{3,1,-2,1},{4,-3,-1,1}};
Print["Augmented matrix [A | H] is ",aug//MatrixForm ];
Print["Rank[A|H]= ",MatrixRank[aug]];
Print[" RREF[ A | H  ] is ",RowReduce[aug]//MatrixForm];
Print["Solution, {x1,x2,x3}=",LinearSolve[A,H]];
Print["Rank of [A|H] and that of A are not the same, hence there is no solution"];

(*Example 1.31, page 28*)
A={{1,2,1},{3,1,-2},{0,0,0}};
(*H={1,2};*)
H={0,0};
Print["A is ",A//MatrixForm];
Print["H is ",H//MatrixForm];
aug={{1,2,1,1},{3,1,-2,1}};
Print["[A|H] is ",aug//MatrixForm];
Print["Rank[A]=",MatrixRank[A]];
Print["Rank[A|H]=",MatrixRank[aug]];
Print["soluton, {x1,x2,x3} is ",LinearSolve[H,A]];