Notebook 1: Mathematical warm-up

Welcome to the first notebook set in FYS1120 this year!

It is important that you understand how the different vector operators such as addition and multiplication works. While working with real problems, however, you will have to perform such calculations on millions of vectors. This is where the aid of a computer comes in handy. We will in the examples below show you how you can preform calculations on vectors quickly. Before you start, have a look at our guide, Get started with IPhyton Notebook, before you start out with these exercises. This guide is available on our webpages:

Get started with IPython Notebook

Warning: Be careful if you copy-paste commands from this page! You may risk indentation errors!

First step is to import needed packages. In this notebook all we need is the pylab-package. Click on the cell below and press shift + Enter in order to evaluate the cell.

In [ ]:
from pylab import *

Vector

Vectors can be represented in Python like this

v = array([1, 4, -2])
u = array([-3, 2, 8])

  • Write these vectors in the cell below and print the output. In order to evaluate the cell, click on the cell and press: shift + Enter
In [ ]:
#v = ...
#u = ...
 
#print ...

Dot product

The dot product of two vectors ${\bf a} = [a_1, a_2, ..., a_n]$ and ${\bf b} = [b_1, b_2, ..., b_n]$ is defined as:

Python has a function for calculating the dot product of two vectors: dot(u,v)

  • Calculate the dot product of u and v.
In [ ]:
# Calculate the dot product of u and v

Cross product

The cross product of two vectors $\mathbf{u}=u_1\mathbf{i}+u_2\mathbf{j}+u_3\mathbf{k} \;$ and $\mathbf{v}=v_1\mathbf{i}+v_2\mathbf{j}+v_3\mathbf{k} \;$ is defined as:

$ \begin{align} \mathbf{u}\times\mathbf{v} =&(u_2v_3-u_3v_2)\mathbf{i}+(u_3v_1-u_1v_3)\mathbf{j}+(u_1v_2-u_2v_1)\mathbf{k}.\\ \end{align} $

Python has a function for the calculating the cross product of two vectors: cross(u,v)

  • Calculate the cross product of u and v.
In [ ]:
# Calculate the cross product of u and v