Vectors, Lists, Matrices

Vectors and Lists

Physical definition of vector is an arrow having length and direction. Many physical quantities are vectors, such as position r, velocity v, angular momentum L, etc. Vector can be defined by its components that are projections of the vector onto the axes of a coordinate system. Components of vectors is what is actually used in operations on them. Vectors, in general, can have any number of components.

Vector in terms of its components (x,y,z = 1,2,3) can be written as

A=(Subscript[A, 1])(Subscript[e, 1])+ (Subscript[A, 2])(Subscript[e, 2])+(Subscript[A, 3])(Subscript[e, 3])  ,

where (Subscript[e, 1]) is a unit vector (vector of length 1) directed along the x-axis etc.

Components of vectors can be stored as Lists. Lists in Mathematica (called arrays in some other systems) store elements within a single mathematical object, and many operations can be performed on Lists as the whole rather than performing operations on individual elements. This saves a lot of computer time and is a big advantage of Mathematica and similar products. One always has to try to formulate many-variable problems in the vector form, i.e., in form of Lists, gaining in elegance and speed.

The simplest form of a List is

MyList={0,4,a,x,f[x],image, sound,list,whatever}

Elements of a List can be any objects. In particular, one can write 3d vectors as

Avec={(Subscript[A, 1]),(Subscript[A, 2]),(Subscript[A, 3])};
Bvec={(Subscript[B, 1]),(Subscript[B, 2]),(Subscript[B, 3])};

Vector components (list elements) can be obtained from Lists as follows

Avec[[1]]

Avec[[2]]

etc.

Products of Vectors

One can define dot product and cross product of two vectors.

Dot product

The dot product of A and B is a scalar defined by

A·B=|A||B|Cos[θ]=AB Cos[θ]

In components, the dot product can be written as

A·B=(Subscript[A, 1])(Subscript[B, 1])+ (Subscript[A, 2])(Subscript[B, 2])+(Subscript[A, 3])(Subscript[B, 3])=(∑_(α=1)^3)(Subscript[A, α])(Subscript[B, α])

Excercise: Prove that the two definitions above are the same.

The dot product is implemented in Mathematica as

Avec.Bvec

The length of a vector, or its absolute value, follows from the Pythagoros theorem

|A|=(Sqrt[((Subscript[A, 1])^2)+((Subscript[A, 2])^2)+((Subscript[A, 3])^2) ])= (Sqrt[A·A])=(Sqrt[(A^2)])

Mathematica gives

(Sqrt[Avec.Avec])

whereas

(Sqrt[(Avec^2)])

is not what we are looking for.

Cross product

Cross product of two vectors A and B is a vector C

A×B=C

that is perpendicular to both A and B (direction according to the screw rule)

and whose absolute value is given by

|C|=|A||B|Sin[θ]

In components, the cross product can be written via a rang-3 determinant

A×B=Det[(({{(Subscript[e, 1]), (Subscript[e, 2]), (Subscript[e, 3])}, {(Subscript[A, 1]), (Subscript[A, 2]), (Subscript[A, 3])}, {(Subscript[B, 1]), (Subscript[B, 2]), (Subscript[B, 3])}}))]=((Subscript[A, 2])(Subscript[B, 3])-(Subscript[A, 3])(Subscript[B, 2]))(Subscript[e, 1])+...

Mathematica calculates cross products as

Avec\[Cross]Bvec

In this formula × (cross) should not be confused with × (Times).

The cross product can also be built in components as

(Subscript[C, α])=(Subscript[ϵ, αβγ])(Subscript[A, β])(Subscript[B, γ       - summation over repeated indices!])

Here (Subscript[ϵ, αβγ]) is the fully antisymmetric 3rd rank tensor:

(Subscript[ϵ, 123])=(Subscript[ϵ, 312])=(Subscript[ϵ, 231])=1
(Subscript[ϵ, 132])=(Subscript[ϵ, 321])=(Subscript[ϵ, 132])=-1

and all other components being zero. In Mathematica it can be realized with the help of the Signature function

Cvec=Table[(∑_(β=1)^3)(∑_(γ=1)^3)Signature[{α,β,γ}]Avec[[β]]Bvec[[γ]],{α,1,3}]

Vector product is antisymmetric

A×B=-B×A

This follows both from the geometrical definition of the vector product and its definition in components. To check it, compute

Avec\[Cross]Bvec+Bvec\[Cross]Avec

or

Avec\[Cross]Bvec==-Bvec\[Cross]Avec

Vector product has a priority over scalar product, and scalar product has a priority over normal product of lists.

More complicated vector expressions

Mixed vector product

Mixed vector product is a dot product of a vector and a cross product of two other vectors and it is invariant with respect to the cyclic permutations of the three vectors

A·(B×C)=C·(A×B)=B·(C×A)

The geometrical interpretation of the mixed product is the volume of the parallelepiped built on the three vectors. In components one has

Avec={(Subscript[A, 1]),(Subscript[A, 2]),(Subscript[A, 3])};    Bvec={(Subscript[B, 1]),(Subscript[B, 2]),(Subscript[B, 3])};     Cvec={(Subscript[C, 1]),(Subscript[C, 2]),(Subscript[C, 3])};
Expand[Avec.Bvec\[Cross]Cvec]

To check symmetry relations, compute

Avec.Bvec\[Cross]Cvec==Cvec.Avec\[Cross]Bvec //Simplify

etc.

Double cross product

Double cross product can be simplified to dot products

A×(B×C)≡B(A·C)-C(A·B)

Check this identity

Avec\[Cross](Bvec\[Cross]Cvec)==Bvec(Avec.Cvec)-Cvec(Avec.Bvec)//Simplify

Dot product of two cross products

(A×B)·(C×D)≡(A·C)(B·D)-(A·D)(B·C)

Check this identity

Avec={(Subscript[A, 1]),(Subscript[A, 2]),(Subscript[A, 3])};    Bvec={(Subscript[B, 1]),(Subscript[B, 2]),(Subscript[B, 3])};     
Cvec={(Subscript[C, 1]),(Subscript[C, 2]),(Subscript[C, 3])};    Dvec={(Subscript[D, 1]),(Subscript[D, 2]),(Subscript[D, 3])};

(Avec\[Cross]Bvec).(Cvec\[Cross]Dvec)==(Avec.Cvec)( Bvec.Dvec)-(Avec.Dvec)( Bvec.Cvec) //Simplify

Note: Here brackets () are unnecessary because of priorities of operations.

Vector functions

Vector functions of scalar arguments can be defined as Lists of ordinary functions

Fvec[x_]:={1,x,(x^2)}

Fvec[x][[3]]

Scalar functions of vector arguments can be defined as functions of Lists

F[XVec_]:=(Sqrt[((XVec[[1]])^2)+((XVec[[2]])^2)+((XVec[[3]])^2)]) (* Absolute value of a vector *)
F[{1,2,3}]

Finally, vector functions of vector arguments can be defined as Lists of functions of Lists

Gvec[XVec_]:={1,XVec[[1]],XVec[[2]]XVec[[3]]}
Gvec[{2,3,4}]

Vector plots

Vector functions can be plotted with VectorPlot, StreamPlot and other commands. For instance, the electric field of a positive point charge up to numerical factors has the

E[r]=(r/(r^3)) .

In the x-y plane (z = 0) there are only x and y components of E. So that in Mathematica we can define

Evec2[x_,y_]:={(x/((((x^2)+(y^2)))^(3/2))),(y/((((x^2)+(y^2)))^(3/2)))}

Now the vector plot of this function in the x-y plane has the form

VectorPlot[Evec2[x,y],{x,-1,1},{y,-1,1},VectorPoints->10]

StreamPlot plots only the directions of the vectors

StreamPlot[Evec2[x,y],{x,-1,1},{y,-1,1}]

Note that Mathematica is not yet developed enough to vector plot functions of a vector argument. For vector plotting, the arguments have to be the vector components.

Exercise: Plot the vector field created by two charges, same and different signs.

Vector plotting is also possible in 3d.

Evec[x_,y_,z_]:={(x/((((x^2)+(y^2)+(z^2)))^(3/2))),(y/((((x^2)+(y^2)+(z^2)))^(3/2))),(z/((((x^2)+(y^2)+(z^2)))^(3/2)))}

VectorPlot3D[Evec[x,y,z],{x,-1,1},{y,-1,1},{z,-1,1},VectorPoints->10]

Unfortunately, StreamPlot3D does not exist. To work around the problem, one can plot E[r](r^2) that is equivalent to StreamPlot3D

VectorPlot3D[Evec[x,y,z]((x^2)+(y^2)+(z^2)),{x,-1,1},{y,-1,1},{z,-1,1},VectorPoints->3]

3d vector plots are not always easy to understand, however.

More general Lists; Matrices

Elements of a List can be Lists. An example considered above is

DataList={{1,2},{2,4},{3,5},{4,5},{5,4},{6,3},{7,2.5}};

Here the elements of DataList are sublists of length 2. Such Lists can be plotted with ListPlot, the first elements of sublists being interpreted as (Subscript[x, i]) and the second elements as (Subscript[y, i]). The elements of such Lists of Lists can be called as follows

DataList[[2]]

DataList[[2]][[1]]
DataList[[2,1]]  (* The same *)

Lists can have whatever complicated substructure. One can construct Lists of Lists of Lists etc. In all cases elements (parts) of the Lists can be addressed by specifying positions of the parts as above. DataList above is also a matrix that can be output explicitly in the matrix form

MatrixForm[DataList]

Lists, as matrices, can be transposed

Transpose[DataList]
MatrixForm[Transpose[DataList]]

Especially important are square matrices

Matrix={{1,2},{2,4}};
MatrixForm[Matrix]

Lists can be generated by several commands, the most general being Table

MyList=Table[{i,(i^2)},{i,1,10}]
MatrixForm[Transpose[MyList]]

or

MyList3=Table[(Subscript[A, i,j,k]),{i,1,3},{j,1,3},{k,1,3}]

This list is an example of a tensor, a structure containing elements labeled by several indices.

The elements of this list can be obtained as

MyList3[[1,2,3]]

etc.

In the above definition, the first index i is the outermost index. One can obtain all elements with a given i simply as.

MyList3[[1]]
MyList3[[2]]

etc.

Elements with a given k can be obtained with the help of All symbol as

MyList3[[All,All,1]]
MyList3[[All,All,2]]

etc.

Lists can be stripped of internal brackets by the command Flatten and its variants

Flatten[MyList3]

Flatten[MyList3,1]