Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
 Documentation /  Mathematica Teacher's Edition /  The Teacher's Book /  More Mathematics /  Vectors and Matrices /

17.1 Vectors

Vectors and matrices in Mathematica TE are simply represented by lists and by lists of lists, respectively.

The representation of vectors and matrices by lists.

Most mathematical functions in Mathematica TE are set up to apply themselves separately to each element in a list. A consequence is that most mathematical functions are applied element by element to matrices and vectors.

The Log applies itself separately to each element in the vector.

In[1]:= Log[ {a, b, c} ]

Out[1]=

The differentiation function D also applies separately to each element in a list.

In[2]:= D[ {x, x^2, x^3}, x ]

Out[2]=

The sum of two vectors is carried out element by element.

In[3]:= {a, b} + {ap, bp}

Out[3]=

If you try to add two vectors with different lengths, you get an error.

In[4]:= {a, b, c} + {ap, bp}

Out[4]=

This adds the scalar 1 to each element of the vector.

In[5]:= 1 + {a, b}

Out[5]=

Any object that is not manifestly a list is treated as a scalar. Here c is treated as a scalar and added separately to each element in the vector.

In[6]:= {a, b} + c

Out[6]=

This multiplies each element in the vector by the scalar k.

In[7]:= k {a, b}

Out[7]=

This takes the dot ("scalar") product of two vectors.

In[8]:= {x, y} . {xp, yp}

Out[8]=

It is important to realize that Mathematica TE treats an object as a vector in a particular operation only if the object is explicitly a list at the time when the operation is done. If the object is not explicitly a list, Mathematica TE always treats it as a scalar. This means that you can get different results, depending on whether you assign a particular object to be a list before or after you do a particular operation.

The object p is treated as a scalar, and added separately to each element in the vector.

In[9]:= {a, b} + p

Out[9]=

This is what happens if you now replace p by the list {c, d}.

In[10]:= % /. p -> {c, d}

Out[10]=

You would have gotten a different result if you had replaced p by {c, d} before you did the first operation.

In[11]:= {a, b} + {c, d}

Out[11]=

Functions for vectors.

This gives a vector of alternating plus and minus ones.

In[12]:= Table[(-1)^i, {i, 8}]

Out[12]=

This gives a vector with symbolic elements. You can use this in deriving general formulas that are valid with any choice of vector components.

In[13]:= Array[a, 4]

Out[13]=

Range gives arithmetic progressions.

In[14]:= v = Range[10, 14, .5]

Out[14]=

This is how to get the number of components in a list or vector.

In[15]:= Length[v]

Out[15]=

This is the third component of the vector.

In[16]:= v[[3]]

Out[16]=


Any questions about topics on this page? Click here to get an individual response.More Information



 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: