Exercise 1

As with all of the exercises you will complete in this course, you will be expected to turn your *.nb file in to the course TA before the next lecture.  Please do so by e-mailing your completed exercise file to Pablo Reyes (pmreyes2@illinois.edu), make sure you name the file using the following notation: “Exn_yourLastname_yourFirstname.nb”, where n is the Exercise number (in this case, 1).  So my submission to Pablo for this exercise would be titled “Ex1_Kudeki_Erhan.nb”.  You will receive full credit for your exercise if it turned in before the next lecture (Lecture n+1).  No late submissions will be accepted.

Objective/Overview:

In today’s exercise, we will focus on how to describe and manipulate vectors and vector fields in Mathematica.  If you have not done so already, please complete the Hands-On Start to Mathematica introductory videos, found in the links on the course website:  https://courses.engr.illinois.edu/ece329.
As for all Exercise sheets, the locations where you are expected to fill in with your own work are shaded in yellow.

Describing and Manipulating Vectors

The Wolfram Language represents vectors as lists.  This is a powerful tool that allows the user to create and manipulate n-dimensional vectors.  However, since we will usually only be working in two or three dimensions, our vectors (or lists) will only generally have 2 or 3 items in the list.

Inputting a Vector

Let’s create a simple three dimensional vector v={a,b,c}={2,4,1}.  List are always denoted by the curly-brackets {}. Note that in Mathematica, we typically use lower-case letters to describe variables and values, since commands always beging with upper-case letters.

v={2,4,1}

Operations on Single Vectors

We can perform a number of operations on a single vector.  For instance, we can extract an element of the vector “v” by using the command “v[[i]]”, where i is the ith element of the vector.

v[[2]]

Mathematically, the magnitude of a vector can be found using |a|=(Sqrt[(a^2)+(b^2)+(c^2)]).  Mathematica allows us to determine the magnitude of the vector using the command Norm[v]:

Norm[v]

You will notice that this expression does not actually calculate the numerical value, but you also know from the Hands-On Start videos that we can do this simply by using the command N[]:

N[Norm[v]]

Finally, we can ask Mathematica to determine the unit vector associated with any vector.  The unit vector of a vector v is a vector of length 1, pointing in the same direction as v:

Normalize[v]

vhat=N[Normalize[v]]

We can make sure this is correct by finding the magnitude of the vector vhat.  In the space below, determine the magnitude of the vector vhat.  Then multiplty vhat by the magnitude of [v].  What do you get?

Vector Math

Mathematica also makes it easy to perform simple math with vectors.  In the following examples, we will define our vectors symbolically.  You will see that Mathematica has no problem performing operations on symbols instead of numbers.  We define our two vectors as:

v1={a1,b1,c1}

v2={a2,b2,c2}

Vector Addition

Let’s start with simple addition. Starting with our previously defined vectors v1 and v2

Now we can add our two vectors:

v1+v2

As you can see, adding two vectors is nothing more than adding the components of the individual vectors.

There are three ways of multiplying vectors, and we will use all three over the course of ECE329.

Scalar Multiplication

First, we can multiple a vector by a scalar.  All this does is scale the magnitude of the vector, keeping the direction the same.  We do this simply by:

v1*m

You can see that each element of the vector was multiplied by the constant scalar m.  Find the unit vector associated with both [v1] and [m*v1], show that they are equivalent:

The Dot Product

The dot product of two vectors gives a scalar.  From a graphical point of view, the dot product of two vectors can be written as v1·v2=|v1||v2|Cosθ, where |v1|and |v2|are the magnitudes of the two vectors and θ is the angle between the two vectors. Mathematically:

v1.v2

the dot product is nothing more than the sum of the products of the elements of the vector.  The command VectorAngle gives the angle between two vectors.  Below, create two numerical vectors (not symbols, but real numbers) and show that the dot product of these two vectors is equivalent to the product of the vector magnitudes and the cosine of the angle between them:

The Cross-Product

The Cross-Product of two vectors gives a vector.  To think about the cross-product graphically, you must recognize that it will be orthogonal (forms a right angle) to each of the two original vectors, and its magnitude will be given by v1·v2=|v1||v2|Sinθ, where |v1|and |v2|are the magnitudes of the two vectors and θ is the angle between the two vectors. You can find the direction of the cross-product using the right hand rule: with your RIGHT hand, point your fingers along the direction of the first vector, then curl your fingers towards the second.  Your thumb will point in the direction of the cross-product!!  
Mathematically, the cross product is a pain in the neck:

\[VerticalSeparator]({{(OverHat[x]), (OverHat[y]), (OverHat[z])}, {ax, ay, az}, {bx, by, bz}})\[VerticalSeparator]=(ay bz-az by)(OverHat[x])+(az bx-ax bz)(OverHat[y])+(ax by-ay by)(OverHat[z])

But Mathematica can take the cross-product in no time, using either the Cross[v1,v2] command, or alternatively using v1 × v2, where you get the × by typing “\” followed by “[Cross]”:

v1\[Cross]v2

Below, create two vectors and show 1) that the magnitude of the cross product of these vectors is equivalent to |v1||v2|Sinθ, and that the cross product is orthogonal to each of the original vectors.

Vector Fields

Vector fields are functions that assign a vector to every point in space.  Mathematica can quickly and easily plot these fields so that you can visualize them quite nicely.  Let’s start with a two dimensional vector field.  To do this, we will use the VectorPlot function.  This function takes as its input the Vector Field expression and the extents of the plot.  Let’s look at a field that is constant in space, in other words, every point has the same vector associated with it.

VectorPlot[{-1,2},{x,-3,3},{y,-3,3}]

We can give our vector field a functional form, so that our vectors vary in space

VectorPlot[{-x^2,2},{x,-3,3},{y,-3,3}]

Mathematica also allows us to plot 3D vector fields! Here we define a function f, which we then use in the VectorPlot3D command.

f={x,y,z}

VectorPlot3D[f,{x,-2,2},{y,-2,2},{z,-2,2}]

As you will learn in the coming weeks, the electric field from a sheet of charge is uniform in space and points away from the sheet of charge.  Plot the vector field for a sheet of charge on the xy plane.  Assume that the magnitude of the electric field is simply 1.  Youcan plot in 2D, 3D, or both!  You will need to figure out a way to flip the sign of the E field across the xy plane.  You can do this with an If statement or by using the Sign command.