1
$\begingroup$

How to write a vector in Mathematica so that one can perform the common operations such as Transpose and Normalize. For example, {1, 1} can be normalized but not transposed. And {{-1}, {1}} can be Transposed but not normalized.

$\endgroup$
  • $\begingroup$ In this case Normalize[{{-1}, {1}}, Norm] does the right thing. $\endgroup$ – Thies Heidecke Dec 3 '19 at 14:54
  • 2
    $\begingroup$ The quote from the documentation "The Wolfram Language represents vectors as lists, and never needs to distinguish between row and column cases. Vectors in the Wolfram Language can always mix numbers and arbitrary symbolic or algebraic elements. The Wolfram Language uses state-of-the-art algorithms to bring platform-optimized performance to operations on extremely long, dense, and sparse vectors". $\endgroup$ – user64494 Dec 3 '19 at 15:00
  • $\begingroup$ @user64494, but it becomes pertinent to define Transpose or HermitianConjugate in some cases. How can one avoid this confusion? $\endgroup$ – Rob Dec 3 '19 at 17:13
  • $\begingroup$ Have you seen the Vector and Matrices tutorial ? In your post {1, 1} is a vector and {-1}, {1}} is a 2x1 matrix. {{1, 1}} would be a 1x2 matrix but not all "vector" functions will take it; e.g. Dot[{{1, 1}}, {{1, 1}}] vs Dot[{1, 1}, {1, 1}]. $\endgroup$ – Edmund Dec 4 '19 at 1:40
  • $\begingroup$ vs Dot[{{1, 1}}, Transpose@{{1, 1}}]. $\endgroup$ – Edmund Dec 4 '19 at 1:45
1
$\begingroup$

Mathematica makes it very easy to define new operations and redefine existing ones. For example, you could write

Unprotect[Normalize];
Normalize[u_?MatrixQ] := Normalize[u, Norm]
Protect[Normalize];

So that

Normalize[{{3}, {4}}]
(* {{3/5}, {4/5}} *)

If you want to make Mathematica behave more like MATLAB in its handling of n x 1 and 1 x n matrices, you shouldn't need to apply too many tweaks.

However, I think that you'd be better advised to understand the benefits of doing things the Mathematica way.

| improve this answer | |
$\endgroup$

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