# Entering Matrices and Vectors

We'll be using numpy primarily for its matrix capabitlities. Numpy stands for NUMerical PYthon and has a lot of other capabitlities we won't use. By importing numpy as `np`

, we only need to prefix commands with `np.`

to use them.

For example, to create a matrix we would use `np.array()`

. You give the command a list of values, with each set of brackets corresponding to one row. Outer brackets should be included.

The row vector $1, 2 $ would be entered as `np.array([[1,2]])`

. Notice the extra outer set of brackets. This is needed to insure row-vectors behave like row-vectors.

Column vectors need to be entered as nested lists so the column vector $\begin{bmatrix} 3 \ 5 \end{bmatrix}$ is entered as `np.array([[3],[5]])`

.

Matrices can be entered as well. For example the matrix $\begin{bmatrix} 1 & 3 \ 5 & 7 \end{bmatrix}$ would be `np.array([[1, 3], [5, 7]])`

. Don't forget the commas in between items.

# Matrix Multiplication

For matrix multiplication we will use the `@`

symbol. Multiplying vector `A`

and `B`

together is `A@B`

. This (mostly) follows the normal matrix multiplication of rows times columns.

Run the cell below and convince yourself that you get the results you'd expect from $\begin{bmatrix} 1 & 2 \end{bmatrix} \cdot \begin{bmatrix} 3 \ 5 \end{bmatrix}$

# Transposing Vectors

If you add `.T`

to a variable name you can get the transpose of a vector (and matrices). Try printing `A.T`

, `B.T`

, and the products `A.T@B.T`

and `B.T@`

A.T` in the cell below.

See if you can figure out why `A.T@B.T`

gives you a 2x2 matrix.

# Complex Numbers

Python follows the engineering convention of using `j`

to indicate imaginary numbers. Placing a `j`

after a number (no spaces) yields a complex number.

Try `1j*1j`

in the cell below. Notice that `j*j`

does not work, you need to have a number immediately in front of the `j`

symbol.

Try out some complex addition and multiplication below.

## Complex Conjugate

You can get the complex conjugate of a number typing `np.conj()`

. Try setting `C = 3 + 4j`

and calculate `C`

times its complex conjugate.

# Standard Basis Vectors

In the cell below I've defined the bras and kets for the standard basis sets (x, y, and z).

Execute the cell below so you can make of these definitions later.

# Orthonormal

The orthonormal condition requires the pairs along each axis are orthogonal to each other (inner product is zero), and that the results are normalized (the inner product of a vector with itself is 1).

# Question 1:

a) Show that all of these definitions are orthonormal along the x-axis, y-axis, and z-axis.

That is, show $\langle \pm x \mid \pm x \rangle = 1$ and $\langle \pm x \mid \mp x \rangle = 0$ and repeat for the y-axis and z-axis.

# "Computers are useless. They only give you answers"

-Pablo Picasso (allegedly)

You should have noticed two slight glitches with your results above. This shows why interpreting results is just as important as making calculations.

# Question 2:

a) What is wrong with the results above and how do you explain why you got the wrong result?

The complex results don't have the same issue but they do add in `0.j`

to your results when they are real.

# Calculating Probabilities

# Question 3:

a) Try calculating the probability to measure "spin-up" along the x-axis if you send the output from "spin-up" along the z-axis into the x-analyzer.

$\lvert \langle +x \mid +z \rangle \rvert^2$

b) Does your answer make sense? Interpret your numerical results.

c) Repeat for a "spin-up" along the y-axis going through an x-analyzer and find the probability to be "spin-up" along the x-axis.

d) Interpret this result.

# Question 4:

## Problem 1.8 from Townsend

The state of a spin-$\frac{1}{2}$ particle is given by

$$\mid \psi \rangle = \frac{i}{\sqrt{3}} \mid +z \rangle + \sqrt{\frac{2}{3}}\mid -z \rangle$$.

a) What are $\langle S_z \rangle $ and $\Delta S_z$ for this state?

*Hint: Setting $\frac{\hbar}{2} = 1$ makes the results easier to interpret. Just keep in mind that doing so means your units are $\frac{\hbar}{2}$.*

b) Interpret your results. Why do they (or don't they) make sense? What do they mean in terms of conducting an experiment?

c) Show that your results for $\Delta S_z$ agree with the value you got from the written homework of $\frac{2\sqrt{2}}{3} \frac{\hbar}{2}$