1.3. Working with vectors using Numpy#
This simple exercises allow you to connect what we have seen before to some basic coding problem. In particular, we will use the NumPy Python library to perform basic operations with vectors.
import numpy as np
The wavefunction, \(\psi(x)\) can be represented as a column vector, \(|\psi\rangle\) . The complex conjugate of the wavefunction, \(\psi^*(x)\) is also represented by a vector which is the complex conjugate transpose of \(|\psi\rangle\).
The normalization of a wavefunction \(\psi(x)\) is an integral
In Dirac notation, it is replaced with a vector equation
The orthogonality of two wavefunctions, \(\psi_i(x)\) and \(\psi_j(x)\), which, in integral notation, is
becomes, in Dirac notation,
Exercise 21
Define two vectors, ϕ1
and ϕ2
, with two elements each, that are normalized, in the sense \(\langle\phi_i|\phi_i\rangle=1\), and orthogonal in the sense that \(\langle\phi_i|\phi_j\rangle=0\).
Hint: In numpy
a vector v
with the two elements 1
and 2
is defined through the command
v=np.array([1,2])
ϕ1 = np.array([]) # replace with your choice for ϕ1
ϕ2 = np.array([]) # replace with your choice for ϕ2
print(f'ϕ1: {ϕ1}')
print(f'ϕ2: {ϕ2}')
Exercise 22
Show that \(\phi_1\) and \(\phi_2\) are normalized and orthonormal
Hint: Here are reported some useful numpy
functions to work with vectors:
v.dot(w)
- inner product (scalar product) of two vectorsv
,w
v.conj()
- complex conjugate of a vectorv
v.conj().dot(w)
- inner product of \(v^\dagger w\)
# Check Normalization
ϕ1_norm = 0 # Replace with vector operation
print(f'<ϕ1|ϕ1> = {ϕ1_norm}')
# Check Orthogonality
ϕ1ϕ2 = 0 # Replace with vector operation
print(f'<ϕ1|ϕ2> = {ϕ1ϕ2}')