2

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)*)
H. Kenan
  • 663
  • 6
  • 13

2 Answers2

4

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 *)
Roman
  • 47,322
  • 2
  • 55
  • 121
4

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]}} *)
John Doty
  • 13,712
  • 1
  • 22
  • 42
  • 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? – murray Feb 28 '19 at 21:05
  • I can only guess that whoever made this design decision judged that extending Normalize to matrices would cause more confusion than enlightenment. – John Doty Feb 28 '19 at 21:19