Template Notebook
Generate

Mathematica Lesson: Vector Computations

In the menu at the top, click Make Your Own Copy to work in Mathematica Online, or click Download to use it in Mathematica.​
​​
​When asked "Do you want to automatically evaluate all the initialization cells in the notebook...?" I recommend "No" so that you can work through each cell one-at-a-time.

Welcome to Mathematica!

Question 1

We enclose vectors in curly brackets and separate their entries with commas. To create the vectors ​​ u⃗ = ⟨2,4,2⟩​​ v⃗ = ⟨−3,5,0⟩​​ w⃗ = ⟨1,1,4⟩​​use
In[]:=
u={2,4,2}​​v={-3,5,0}​​(* Now define w below! *)​​
Do Shift-Return (Shift-Enter) to get each stored as an output. When asked if you want to Evaluate Initialization Cells(If you are having trouble, post on our forum!)

Question 2

Like most programs,​
​​
​  + means addition,​
​  - means subtraction, and​
​  * means regular multiplication ​
​​
​in Mathematica. Try these operations on the vectors u⃗ , v⃗ , and w⃗ that you have created. Remember that you need to do Shift-Return (Shift-Enter) to evaluate each expression.​
​​
​(You may accidentally type 𝟦𝗎, and you will discover that Mathematica accepts this, since your meaning is not ambiguous. However, if you have variables 𝗑 and 𝗒, you must do 𝗑∗𝗒 to multiply them together. Mathematica would treat 𝗑𝗒 as a separate two-letter variable.)​
​​
​Once you have a handle on this, enter the result of 4u⃗ − 10v⃗ + 9w⃗ in Moodle. Use commas and do not include any unnecessary spacing. For example, if the answer is ⟨1,2,3⟩, type {1,2,3} (with no spacing before or after the commas).
(* Compute 4*u-10*v+9*w below *)

Information

Next, let's see how to compute dots products and magnitudes in Mathematica. We will introduce the following commands:
◼
  • Dot
  • ◼
  • .
  • ◼
  • Sqrt
  • ◼
  • N
  • We will also see the following "tricks"
    ◼
  • % - a way of plugging in a recent answer
  • ◼
  • // a way of including some styling commands
  • ◼
  • TraditionalForm (below) - a way of printing the output more traditionally. This is good for WebAssign.
  • In[]:=
    (* Compare these *)​​r*Cos[t]​​r*Cos[t]//TraditionalForm

    Dot product and vector magnitude computations

    Question 3

    In the space below, create the vectors​​ a={1,2,3}​​     b={4,3,10}​​​​Do Shift-Return (Shift-Enter) to get each stored as an output.​​​​Then try their dot product: both​​ a.b​​    ​​and​​​​ Dot[a,b]​​    ​​will work. What is the output? (Enter the answer in Moodle.)
    (* Define the vectors*)​​​​​​(* Now compute their dot product! *)​​

    Question 4

    Try the following two commands (you should get the same answer):​​​​ Dot[a,a]​​ a.a​​​​(Note: you need to do Shift+Return to evaluate each one.)
    ​

    Question 5

    What is the magnitude of vector a⃗ ? To get this, we will use the fact that ‖a⃗ ‖= Sqrt[a⃗ ⋅ a⃗]. Try
    magnitudea=Sqrt[a.a]
    Your answer should be Sqrt[14], which we have now stored as a new variable called 𝗆𝖺𝗀𝗇𝗂𝗍𝗎𝖽𝖾𝖺.​
    ​​
    ​Mathematica gives exact answers, which is good because that's what WebAssign expects! If you want a decimal approximation of the answer, you can do one of the following:
    N[%]​​(* or *)​​%//N (* Careful... % always means "the very last thing Mathematica computed" When in doubt, don't use it. *)​​(* or *)​​magnitudea=Sqrt[a.a]//N (* Put this answer in Moodle. *)
    Note 1: 𝖭 is never a good choice for a variable in Mathematica. In fact it's not even possible. (Similarly, C and D are not possible names for variables.)​
    ​Note 2: Be careful with %. It always means "the last thing computed (anywhere in the notebook)" and not "what was computed on the line just above."

    Question 6

    Let z⃗ = ⟨1,2,3⟩. Use Mathematica to find a unit-length (i.e., the magnitude is 1) vector which points in the same direction as z⃗ . Remember, ​​ ‖z⃗ ‖​​ in Mathematica is 𝖲𝗊𝗋𝗍[𝖣𝗈𝗍[𝗓,𝗓]] or alternatively Sqrt[z.z].​​​​Use the 𝖭 command to give your answer to the nearest hundredth. (Your answer will not be marked correct otherwise.) However, please observe that you can get an answer in exact form by not using​​𝖭.
    (* Step 1: Define the vector z *)​​​​(* Step 2: Compute Sqrt[Dot[z,z]] or Sqrt[z.z] *)​​​​(* Step 3: Find the decimal approximation. *)
    (a) Find a unit vector parallel to z⃗ which points in the same direction: (to the nearest hundredth)
    (* Now try z/Sqrt[z.z]. Use N to get the decimal approximation *)
    (b) Next find a unit vector parallel to z⃗ which points in the opposite direction: (to the nearest hundredth)
    (* Now try -z/Sqrt[z.z]. Use N to get the decimal approximation *)

    Information

    This page is a little more advanced (I would not expect you to write the following command from scratch).​
    ​​
    ​As we move through these activities we will learn to do basic plots. Just for fun, here is a fairly advanced plot of the vectors u⃗ , v⃗, and w⃗  from Question 1.
    Graphics3D[{Black,Arrow[{{0,0,0},u}],Blue,Arrow[{{0,0,0},v}],​​Red,Arrow[{{0,0,0},w}]},AxesTrue,AxesOrigin{0,0,0},BoxedFalse,AxesLabel{x,y,z}]
    Perhaps you can modify this to plot other vectors.