Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.1K Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to join the coefficient matrix and column vector for a augmented matrix

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}}
POSTED BY: Peter Burbery
3 Replies
Posted 2 years ago

For the depth 2 case, Join with a levelspec can be used.

Join[coefficientMarix, {{9}, {5}, {2}}, 2]
POSTED BY: Rohit Namjoshi
Posted 2 years ago

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]]
POSTED BY: Eric Rimbey

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.

POSTED BY: Peter Burbery
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard