Linear Algebra and Quantum Mechanics Crash Course

Mathematics and Linear Algebra Overview

In the programming language of your choice, define the following variables and complete the following calculations. You may use built-in functions (such at the Numpy library) or create your own functions. Verify that your answers are correct either by hand or using an online linear algebra solver such as Wolfram Alpha.

  1. (8pts.) Define two real scalars (a and b) and give them any valid values. Compute the addition, subtraction, multiplication, and division of a and b.
# Define two real scalars and give them any valid values
a = 3.5
b = -4.27
print("a and b:", a,b)

# Compute the addition
add = a+b
print("Addition:", add)

# subtraction
sub = a-b
print("Subtraction:", sub)

# multiplication
mul = a*b
print("Multiplication:", mul)

# and division of a and b
div = a/b
print("Division:", div)
a and b: 3.5 -4.27
Addition: -0.7699999999999996
Subtraction: 7.77
Multiplication: -14.944999999999999
Division: -0.8196721311475411
  1. (10 pts.) Define two imaginary scalars (c and d) and give them any valid values. Compute the addition, subtraction, and multiplication of c and d. Also compute the modulus of c and the modulus squared of d.
# Import numpy for conjugate()
import numpy as np

# Define two imaginary scalars (c and d) and give them any valid values. 
c = -5j
d = 2+6j
print("c and d:", c,d)

# Compute the addition, 
add = c+d
print("Addition:", add)

# subtraction, 
sub = a-b
print("Subtraction:", sub)

# and multiplication of c and d. 
mul = a*b
print("Multiplication:", a*b)

# Also compute the modulus of c 
mod_c = np.sqrt(c*np.conjugate(c))
print("Modulus of c:", mod_c)

# and the modulus squared of d.
mod_squared_d = d*np.conjugate(d)
print("Modulus squared of d:", mod_squared_d)
c and d: (-0-5j) (2+6j)
Addition: (2+1j)
Subtraction: 7.77
Multiplication: -14.944999999999999
Modulus of c: (5+0j)
Modulus squared of d: (40+0j)
  1. (16 pts.) Define two vectors (e and f) of length 3. The elements can be real or imaginary. Compute the addition, subtraction, dot product, and cross product of e and f. Find the magnitude of e and the unit vector of f.
# Define two vectors (e and f) of length 3. The elements can be real or imaginary. 
e = np.array([1,2j,4-3j])
f = np.array([4.5, 3.33, 8.7])
print("e and f:", e,f)

# Compute the addition,
add = e+f
print("Addition:", add)

# subtraction, 
sub = e-f
print("Subtraction:", sub)

# dot product, 
dot = e.dot(f)
print("Dot Product:", dot)

# and cross product of e and f. 
cross = np.cross(e,f)
print("Cross Product:", cross)

# Find the magnitude of e 
mag_e = np.linalg.norm(e)
print("Magnitude of e:", mag_e)

# and the unit vector of f.
mag_f = np.linalg.norm(f)
unit_vector_f = f/mag_f
print("Unit vector of f:", unit_vector_f)
e and f: [1.+0.j 0.+2.j 4.-3.j] [4.5  3.33 8.7 ]
Addition: [ 5.5 +0.j  3.33+2.j 12.7 -3.j]
Subtraction: [-3.5 +0.j -3.33+2.j -4.7 -3.j]
Dot Product: (39.3-19.439999999999998j)
Cross Product: [-13.32+27.39j   9.3 -13.5j    3.33 -9.j  ]
Magnitude of e: 5.477225575051661
Unit vector of f: [0.43497268 0.32187978 0.84094719]
  1. (16 pts.) Define two 2x2 matrices (A and B). The elements can be real or imaginary. Compute AB, BA, the commutator of A and B, and the addition and subtraction of A and B. Compute the transpose and inverse of A, the complex conjugate of B, and the adjoint of A.
# Define two 2x2 matrices (A and B). The elements can be real or imaginary. 
A = np.array([[0,1],[1,0]])
B = np.array([[1,0], [0,-1]])
print("A and B:", A,B)

# Compute AB, 
AB = A@B
print("AB:", AB)

# BA, 
BA = B@A
print("BA:", BA)

# the commutator of A and B, 
comm = AB-BA
print("Comutator:", comm)

# and the addition 
add = A+B
print("Addition:", add)

# and subtraction of A and B. 
sub = A-B
print("Subtraction:", sub)

# Compute the transpose 
trans_A = A.T
print("Transpose of A:", trans_A)

# and inverse of A, 
inv_A = np.linalg.inv(A)
print("Inverse of A:", inv_A)

# the complex conjugate of B,
com_conj_B = B.conj()
print("Complex Conjugate of B:", com_conj_B)

# and the adjoint of A.
adjoint_A = A.T.conj()
print("Adjoint of A:", adjoint_A)
A and B: [[0 1]
 [1 0]] [[ 1  0]
 [ 0 -1]]
AB: [[ 0 -1]
 [ 1  0]]
BA: [[ 0  1]
 [-1  0]]
Comutator: [[ 0 -2]
 [ 2  0]]
Addition: [[ 1  1]
 [ 1 -1]]
Subtraction: [[-1  1]
 [ 1  1]]
Transpose of A: [[0 1]
 [1 0]]
Inverse of A: [[0. 1.]
 [1. 0.]]
Complex Conjugate of B: [[ 1  0]
 [ 0 -1]]
Adjoint of A: [[0 1]
 [1 0]]
o = np.array([[0,1,0],[1,-1j,0],[0,0,2]])
vals, vecs = np.linalg.eig(o)
vals[0], vecs[:,0]
((0.8660254037844384-0.5j),
 array([ 0.70710678+0.j        ,  0.61237244-0.35355339j,
        -0.        +0.j        ]))