I am wondering how to join a coefficient matrix like the matrix with the size 3 by 3:
{{1, 0, 5}, {-2, 2, 0}, {1, -8, -5}
with another column vector like
{9,5,2}
to form an augmented matrix like
{{1, 0, 5, 9}, {-2, 2, 0, 5}, {1, -8, -5, 2}}
I am wondering how to join a coefficient matrix like the matrix with the size 3 by 3:
{{1, 0, 5}, {-2, 2, 0}, {1, -8, -5}
with another column vector like
{9,5,2}
to form an augmented matrix like
{{1, 0, 5, 9}, {-2, 2, 0, 5}, {1, -8, -5, 2}}
I figured it out. If the column vector has an ArrayDepth of 1 like {9,5,2}, the following will work.
MapThread[Append, {coefficientMatrix, {9, 5, 2}}] // MatrixForm
If the column vector has an ArrayDepth of 2 like {{9},{5},{2}} then this will work:
MapThread[
Append, {coefficientMatrix, Flatten[{{9}, {5}, {2}}]}] // MatrixForm
To get a coefficient matrix,
coefficientMatrix = {{1, 0, 5}, {-2, 2, 0}, {1, -8, -5}}
Map[Most][
MapThread[Append, {coefficientMatrix, {9, 5, 2}}]] // MatrixForm
and the column vector:
Map[Last][
MapThread[Append, {coefficientMatrix, {9, 5, 2}}]] // MatrixForm
Another option is to use the Resource Functions AugmentedMatrix and CoefficientMatrix created by Dennis M Schneider.
Nice solutions! I’ll add a couple of alternatives just for inspiration.
To get the augmented matrix:
augmentedMatrix = ArrayPad[coefficientMatrix, {{0, 0}, {0, 1}}, columnVector]
To get back the coefficient matrix and column vector:
augmentedMatrix[[All, 1 ;; -2]]
augmentedMatrix[[All, -1]]
For the depth 2 case, Join with a levelspec can be used.
Join[coefficientMarix, {{9}, {5}, {2}}, 2]