2
$\begingroup$

I have this simple example in which I am trying to write a column vector (ket vector) and then I want to normalize it. It seems that ther is something wrong, leading to an error message

"The first argument is not a number or a vector,... "

 myVec = {{1}, {2}};
Normalize[myVec]

How can one fix this. What is the best way of writing a ket vector and bra vector in Mathematica?

Edit: Related to some comments below, I want to added the following:

 mat1 = {{1}, {2}};
Dimensions[mat1](*(2,1)*)

    mat2 = {{1, 2}};
Dimensions[mat2](*(1,2)*)

    mat3 = {1, 2};
Dimensions[mat3](*(2)*)
$\endgroup$
4
  • $\begingroup$ myVec = {1, 2} $\endgroup$ Commented Feb 27, 2019 at 8:23
  • $\begingroup$ Would this be a row or a column vector? $\endgroup$
    – H. Kenan
    Commented Feb 27, 2019 at 8:29
  • $\begingroup$ No. Normalize accepts a vector, in Wolfram language, which means a List with an ArrayDepth 1; a row/column vector is represented by a matrix (a List of Lists) with an ArrayDepth 2, unacceptable. $\endgroup$ Commented Feb 27, 2019 at 8:32
  • 2
    $\begingroup$ Tobias, there’s no practical distinction between row and column vectors in Mathematica. They are expressed the same way. You keep track of their “meaning” as you see fit. $\endgroup$
    – MarcoB
    Commented Feb 27, 2019 at 13:13

2 Answers 2

4
$\begingroup$

Mathematica's vectors are always simple lists (tutorial). In this sense there is no distinction between row vectors and column vectors, unlike Matlab etc.

A propos ket vs bra: if you define a state ket

p = {1, 2};

then the corresponding bra is simply

ps = Conjugate[p];

and is also a vector. The scalar product would be

ps.p
(* 5 *)

You could even define a scalar-product function

scp[a_?VectorQ, b_?VectorQ] /; Length[a] == Length[b] := Conjugate[a].b

and then calculate

scp[p,p]
(* 5 *)
$\endgroup$
4
$\begingroup$

If you want to make vectors a special case of matrices (this can be useful for some applications), you can normalize this way:

myVec/Norm[myVec]
(* {{1/Sqrt[5]}, {2/Sqrt[5]}} *)
$\endgroup$
2
  • $\begingroup$ It's a bit odd that Mathematica can handle Norm[v] when v is a "column vector", i.e., a list of 1-element lists, yet Normalize cannot. Is there some good reason that Normalize should not equally generalize like that? $\endgroup$
    – murray
    Commented Feb 28, 2019 at 21:05
  • $\begingroup$ I can only guess that whoever made this design decision judged that extending Normalize to matrices would cause more confusion than enlightenment. $\endgroup$
    – John Doty
    Commented Feb 28, 2019 at 21:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.