Skip to main content
added 155 characters in body
Source Link
Sjoerd C. de Vries
  • 66.1k
  • 15
  • 189
  • 327

Mathematica does not have the concept of row or column vectors like you may be used to. The concept isn't really necessary either and is just a convention to visualize the dot product (although I know there are people that vehemently object to this statement).

In dot products like $M\cdot\vec{x}$ and $\vec{x}^{^\top}\cdot M$ Mathematica uses $\vec{x}$ as your column and row vector automatically. Both are entered in Mathematica as the same list.

{{1, 2}, {3, 4}}.{5, 6}
(* {17, 39} *)

{5, 6}.{{1, 2}, {3, 4}}
(* {23, 34} *)

Of course, this means that the length of the vector must be equal to the number of columns in the matrix in the former case, and to the number of rows in the latter case.

So, this doesn't work (2x3 matrix):

{{1, 2, 1}, {3, 4, 1}}.{5, 6}

During evaluation of Dot::dotsh: Tensors {{1,2,1},{3,4,1}} and {5,6} have incompatible shapes. >>

(* {{1, 2, 1}, {3, 4, 1}}.{5, 6} *)

and this works (3x2 matrix):

{{1, 2}, {3, 4}, {1, 1}}.{5, 6}
(* {17, 39, 11} *)

If you insist on using column and row vectors, you can mimic them by using similarly looking matrices. The matrix equivalent of a column vector would be {{x1}, {x2},...,{xn}}. The equivalent of a row vector would be {{x1, x2,...,xn}}. If you use MatrixForm or TableForm they display just like column and row vectors would, except that they are still matrices in disguise (nx1 and 1xn ones, respectively). Those matrices behave in dot products just like their row and column vector brethren would (inin languages that have them), but remember, they are not necessary at all in Mathematica.

{{1, 2}, {3, 4}}.{{5}, {6}}
(* {{17}, {39}} *)

{{5, 6}}.{{1, 2}, {3, 4}}
(* {{23, 34}} *)

The above code typeset in TraditionalForm (just Ctrl+Alt+T of the above lines) displays as:

Mathematica graphics

The main disadvantage of this technique is having to deal with extra curly brackets that have to be removed when you want to use the resulting vector as a list, and the fact that you have to change the brackets depending on the position in the dot product. Additionally, there are functions that expect Mathematica vectors (simple lists) that won't work when provided with their matrix emulations.

Mathematica does not have the concept of row or column vectors like you may be used to. The concept isn't really necessary either and is just a convention to visualize the dot product (although I know there are people that vehemently object to this statement).

In dot products like $M\cdot\vec{x}$ and $\vec{x}^{^\top}\cdot M$ Mathematica uses $\vec{x}$ as your column and row vector automatically. Both are entered in Mathematica as the same list.

{{1, 2}, {3, 4}}.{5, 6}
(* {17, 39} *)

{5, 6}.{{1, 2}, {3, 4}}
(* {23, 34} *)

Of course, this means that the length of the vector must be equal to the number of columns in the matrix in the former case, and to the number of rows in the latter case.

So, this doesn't work (2x3 matrix):

{{1, 2, 1}, {3, 4, 1}}.{5, 6}

During evaluation of Dot::dotsh: Tensors {{1,2,1},{3,4,1}} and {5,6} have incompatible shapes. >>

(* {{1, 2, 1}, {3, 4, 1}}.{5, 6} *)

and this works (3x2 matrix):

{{1, 2}, {3, 4}, {1, 1}}.{5, 6}
(* {17, 39, 11} *)

If you insist on using column and row vectors, you can mimic them by using similarly looking matrices. The matrix equivalent of a column vector would be {{x1}, {x2},...,{xn}}. The equivalent of a row vector would be {{x1, x2,...,xn}}. If you use MatrixForm or TableForm they display just like column and row vectors would, except that they are still matrices in disguise (nx1 and 1xn ones, respectively). Those matrices behave just like their row and column vector brethren would (in languages that have them), but remember, they are not necessary at all in Mathematica.

{{1, 2}, {3, 4}}.{{5}, {6}}
(* {{17}, {39}} *)

{{5, 6}}.{{1, 2}, {3, 4}}
(* {{23, 34}} *)

The above code typeset in TraditionalForm (just Ctrl+Alt+T of the above lines) displays as:

Mathematica graphics

The main disadvantage of this technique is having to deal with extra curly brackets that have to be removed when you want to use the resulting vector as a list, and the fact that you have to change the brackets depending on the position in the dot product.

Mathematica does not have the concept of row or column vectors like you may be used to. The concept isn't really necessary either and is just a convention to visualize the dot product (although I know there are people that vehemently object to this statement).

In dot products like $M\cdot\vec{x}$ and $\vec{x}^{^\top}\cdot M$ Mathematica uses $\vec{x}$ as your column and row vector automatically. Both are entered in Mathematica as the same list.

{{1, 2}, {3, 4}}.{5, 6}
(* {17, 39} *)

{5, 6}.{{1, 2}, {3, 4}}
(* {23, 34} *)

Of course, this means that the length of the vector must be equal to the number of columns in the matrix in the former case, and to the number of rows in the latter case.

So, this doesn't work (2x3 matrix):

{{1, 2, 1}, {3, 4, 1}}.{5, 6}

During evaluation of Dot::dotsh: Tensors {{1,2,1},{3,4,1}} and {5,6} have incompatible shapes. >>

(* {{1, 2, 1}, {3, 4, 1}}.{5, 6} *)

and this works (3x2 matrix):

{{1, 2}, {3, 4}, {1, 1}}.{5, 6}
(* {17, 39, 11} *)

If you insist on using column and row vectors, you can mimic them by using similarly looking matrices. The matrix equivalent of a column vector would be {{x1}, {x2},...,{xn}}. The equivalent of a row vector would be {{x1, x2,...,xn}}. If you use MatrixForm or TableForm they display just like column and row vectors would, except that they are still matrices in disguise (nx1 and 1xn ones, respectively). Those matrices behave in dot products just like their row and column vector brethren would in languages that have them, but remember, they are not necessary at all in Mathematica.

{{1, 2}, {3, 4}}.{{5}, {6}}
(* {{17}, {39}} *)

{{5, 6}}.{{1, 2}, {3, 4}}
(* {{23, 34}} *)

The above code typeset in TraditionalForm (just Ctrl+Alt+T of the above lines) displays as:

Mathematica graphics

The main disadvantage of this technique is having to deal with extra curly brackets that have to be removed when you want to use the resulting vector as a list, and the fact that you have to change the brackets depending on the position in the dot product. Additionally, there are functions that expect Mathematica vectors (simple lists) that won't work when provided with their matrix emulations.

added 272 characters in body
Source Link
Sjoerd C. de Vries
  • 66.1k
  • 15
  • 189
  • 327

Mathematica does not have the concept orof row or column vectors like you may be used to. The concept isn't really necessary either and is just a convention to visualize the dot product (although I know there are people that vehemently object to this statement).

In dot products like $M\cdot\vec{x}$ and $\vec{x}\cdot M$$\vec{x}^{^\top}\cdot M$ Mathematica uses $\vec{x}$ as your column and row vector automatically. Both are entered in Mathematica as the same list.

{{1, 2}, {3, 4}}.{5, 6}
(* {17, 39} *)

{5, 6}.{{1, 2}, {3, 4}}
(* {23, 34} *)

Of course, this means that the length of the vector must be equal to the number of columns in the matrix in the former case, and to the number of rows in the latter case.

So, this doesn't work (2x3 matrix):

{{1, 2, 1}, {3, 4, 1}}.{5, 6}

During evaluation of Dot::dotsh: Tensors {{1,2,1},{3,4,1}} and {5,6} have incompatible shapes. >>

(* {{1, 2, 1}, {3, 4, 1}}.{5, 6} *)

and this works (3x2 matrix):

{{1, 2}, {3, 4}, {1, 1}}.{5, 6}
(* {17, 39, 11} *)

If you insist on using column and row vectors, you can mimic them by using similarly looking matrices. The matrix equivalent of a columncolumn vector would be {{x1}, {x2},...,{xn}}. The equivalent of a rowrow vector would be {{x1, x2,...,xn}}. If you use MatrixForm or TableForm they display just like column and row vectors would, except that they are still matrices in disguise (nx1 and 1xn ones, respectively). Those matrices behave just like their row and column vector brethren would (in languages that have them), but remember, they are not necessary at all in Mathematica.

{{1, 2}, {3, 4}}.{{5}, {6}}
(* {{17}, {39}} *)

{{5, 6}}.{{1, 2}, {3, 4}}
(* {{23, 34}} *)

The above code typeset in TraditionalForm (just Ctrl+Alt+T of the above lines) displays as:

Mathematica graphics

The main disadvantage of this technique is having to deal with extra curly brackets that have to be removed when you want to use the resulting vector as a list, and the fact that you have to change the brackets depending on the position in the dot product.

Mathematica does not have the concept or row or column vectors like you may be used to. The concept isn't really necessary either and is just a convention to visualize the dot product (although I know there are people that vehemently object to this statement).

In dot products like $M\cdot\vec{x}$ and $\vec{x}\cdot M$ Mathematica uses $\vec{x}$ as your column and row vector automatically. Both are entered in Mathematica as the same list.

{{1, 2}, {3, 4}}.{5, 6}
(* {17, 39} *)

{5, 6}.{{1, 2}, {3, 4}}
(* {23, 34} *)

Of course, this means that the length of the vector must be equal to the number of columns in the matrix in the former case, and to the number of rows in the latter case.

So, this doesn't work (2x3 matrix):

{{1, 2, 1}, {3, 4, 1}}.{5, 6}

During evaluation of Dot::dotsh: Tensors {{1,2,1},{3,4,1}} and {5,6} have incompatible shapes. >>

(* {{1, 2, 1}, {3, 4, 1}}.{5, 6} *)

and this works (3x2 matrix):

{{1, 2}, {3, 4}, {1, 1}}.{5, 6}
(* {17, 39, 11} *)

If you insist on using column and row vectors, you can mimic them by using similarly looking matrices. The matrix equivalent of a column vector would be {{x1}, {x2},...,{xn}}. The equivalent of a row vector would be {{x1, x2,...,xn}}. If you use MatrixForm or TableForm they display just like column and row vectors would, except that they are still matrices in disguise (nx1 and 1xn ones, respectively). Those matrices behave just like their row and column vector brethren would (in languages that have them), but remember, they are not necessary at all in Mathematica.

{{1, 2}, {3, 4}}.{{5}, {6}}
(* {{17}, {39}} *)

{{5, 6}}.{{1, 2}, {3, 4}}
(* {{23, 34}} *)

The above code typeset in TraditionalForm (just Ctrl+Alt+T of the above lines) displays as:

Mathematica graphics

Mathematica does not have the concept of row or column vectors like you may be used to. The concept isn't really necessary either and is just a convention to visualize the dot product (although I know there are people that vehemently object to this statement).

In dot products like $M\cdot\vec{x}$ and $\vec{x}^{^\top}\cdot M$ Mathematica uses $\vec{x}$ as your column and row vector automatically. Both are entered in Mathematica as the same list.

{{1, 2}, {3, 4}}.{5, 6}
(* {17, 39} *)

{5, 6}.{{1, 2}, {3, 4}}
(* {23, 34} *)

Of course, this means that the length of the vector must be equal to the number of columns in the matrix in the former case, and to the number of rows in the latter case.

So, this doesn't work (2x3 matrix):

{{1, 2, 1}, {3, 4, 1}}.{5, 6}

During evaluation of Dot::dotsh: Tensors {{1,2,1},{3,4,1}} and {5,6} have incompatible shapes. >>

(* {{1, 2, 1}, {3, 4, 1}}.{5, 6} *)

and this works (3x2 matrix):

{{1, 2}, {3, 4}, {1, 1}}.{5, 6}
(* {17, 39, 11} *)

If you insist on using column and row vectors, you can mimic them by using similarly looking matrices. The matrix equivalent of a column vector would be {{x1}, {x2},...,{xn}}. The equivalent of a row vector would be {{x1, x2,...,xn}}. If you use MatrixForm or TableForm they display just like column and row vectors would, except that they are still matrices in disguise (nx1 and 1xn ones, respectively). Those matrices behave just like their row and column vector brethren would (in languages that have them), but remember, they are not necessary at all in Mathematica.

{{1, 2}, {3, 4}}.{{5}, {6}}
(* {{17}, {39}} *)

{{5, 6}}.{{1, 2}, {3, 4}}
(* {{23, 34}} *)

The above code typeset in TraditionalForm (just Ctrl+Alt+T of the above lines) displays as:

Mathematica graphics

The main disadvantage of this technique is having to deal with extra curly brackets that have to be removed when you want to use the resulting vector as a list, and the fact that you have to change the brackets depending on the position in the dot product.

added 2 characters in body
Source Link
Sjoerd C. de Vries
  • 66.1k
  • 15
  • 189
  • 327

Mathematica does not have the concept or row or column vectors like you may be used to. The concept isn't really necessary either and is just a convention to visualize the dot product (although I know there are people that vehemently object to this statement).

In dot products like $M\cdot\vec{x}$ and $\vec{x}\cdot M$ Mathematica uses $\vec{x}$ as your column and row vector automatically. Both are entered in Mathematica as the same list.

{{1, 2}, {3, 4}}.{5, 6}
(* {17, 39} *)

{5, 6}.{{1, 2}, {3, 4}}
(* {23, 34} *)

Of course, this means that the length of the vector must be equal to the number of columns in the matrix in the former case, and to the number of rows in the latter case.

So, this doesn't work (2x3 matrix):

{{1, 2, 1}, {3, 4, 1}}.{5, 6}

During evaluation of Dot::dotsh: Tensors {{1,2,1},{3,4,1}} and {5,6} have incompatible shapes. >>

(* {{1, 2, 1}, {3, 4, 1}}.{5, 6} *)

and this works (3x2 matrix):

{{1, 2}, {3, 4}, {1, 1}}.{5, 6}
(* {17, 39, 11} *)

If you insist on using column and row vectors, you can mimic them by using similarsimilarly looking matrices. The matrix equivalent of a column vector would be {{x1}, {x2},...,{xn}}. The equivalent of a row vector would be {{x1, x2,...,xn}}. If you use MatrixForm or TableForm they display just like column and row vectors would, except that they are still matrices in disguise (nx1 and 1xn ones, respectively). Those matrices behave just like their row and column vector brethren would in(in languages that have them), but remember, they are not necessary at all in Mathematica.

{{1, 2}, {3, 4}}.{{5}, {6}}
(* {{17}, {39}} *)

{{5, 6}}.{{1, 2}, {3, 4}}
(* {{23, 34}} *)

The above code typeset in TraditionalForm (just Ctrl+Alt+T of the above lines) displays as:

Mathematica graphics

Mathematica does not have the concept or row or column vectors like you may be used to. The concept isn't really necessary either and is just a convention to visualize the dot product (although I know there are people that vehemently object to this statement).

In dot products like $M\cdot\vec{x}$ and $\vec{x}\cdot M$ Mathematica uses $\vec{x}$ as your column and row vector automatically. Both are entered in Mathematica as the same list.

{{1, 2}, {3, 4}}.{5, 6}
(* {17, 39} *)

{5, 6}.{{1, 2}, {3, 4}}
(* {23, 34} *)

Of course, this means that the length of the vector must be equal to the number of columns in the matrix in the former case, and to the number of rows in the latter case.

So, this doesn't work (2x3 matrix):

{{1, 2, 1}, {3, 4, 1}}.{5, 6}

During evaluation of Dot::dotsh: Tensors {{1,2,1},{3,4,1}} and {5,6} have incompatible shapes. >>

(* {{1, 2, 1}, {3, 4, 1}}.{5, 6} *)

and this works (3x2 matrix):

{{1, 2}, {3, 4}, {1, 1}}.{5, 6}
(* {17, 39, 11} *)

If you insist on using column and row vectors, you can mimic them by using similar looking matrices. The matrix equivalent of a column vector would be {{x1}, {x2},...,{xn}}. The equivalent of a row vector would be {{x1, x2,...,xn}}. If you use MatrixForm or TableForm they display just like column and row vectors would, except that they are still matrices in disguise (nx1 and 1xn ones, respectively). Those matrices behave just like their row and column vector brethren would in languages that have them, but remember, they are not necessary at all in Mathematica.

{{1, 2}, {3, 4}}.{{5}, {6}}
(* {{17}, {39}} *)

{{5, 6}}.{{1, 2}, {3, 4}}
(* {{23, 34}} *)

The above code typeset in TraditionalForm (just Ctrl+Alt+T of the above lines) displays as:

Mathematica graphics

Mathematica does not have the concept or row or column vectors like you may be used to. The concept isn't really necessary either and is just a convention to visualize the dot product (although I know there are people that vehemently object to this statement).

In dot products like $M\cdot\vec{x}$ and $\vec{x}\cdot M$ Mathematica uses $\vec{x}$ as your column and row vector automatically. Both are entered in Mathematica as the same list.

{{1, 2}, {3, 4}}.{5, 6}
(* {17, 39} *)

{5, 6}.{{1, 2}, {3, 4}}
(* {23, 34} *)

Of course, this means that the length of the vector must be equal to the number of columns in the matrix in the former case, and to the number of rows in the latter case.

So, this doesn't work (2x3 matrix):

{{1, 2, 1}, {3, 4, 1}}.{5, 6}

During evaluation of Dot::dotsh: Tensors {{1,2,1},{3,4,1}} and {5,6} have incompatible shapes. >>

(* {{1, 2, 1}, {3, 4, 1}}.{5, 6} *)

and this works (3x2 matrix):

{{1, 2}, {3, 4}, {1, 1}}.{5, 6}
(* {17, 39, 11} *)

If you insist on using column and row vectors, you can mimic them by using similarly looking matrices. The matrix equivalent of a column vector would be {{x1}, {x2},...,{xn}}. The equivalent of a row vector would be {{x1, x2,...,xn}}. If you use MatrixForm or TableForm they display just like column and row vectors would, except that they are still matrices in disguise (nx1 and 1xn ones, respectively). Those matrices behave just like their row and column vector brethren would (in languages that have them), but remember, they are not necessary at all in Mathematica.

{{1, 2}, {3, 4}}.{{5}, {6}}
(* {{17}, {39}} *)

{{5, 6}}.{{1, 2}, {3, 4}}
(* {{23, 34}} *)

The above code typeset in TraditionalForm (just Ctrl+Alt+T of the above lines) displays as:

Mathematica graphics

deleted 3 characters in body
Source Link
Sjoerd C. de Vries
  • 66.1k
  • 15
  • 189
  • 327
Loading
Source Link
Sjoerd C. de Vries
  • 66.1k
  • 15
  • 189
  • 327
Loading