Four vectors
We want to define our own struct in Julia to deal with four vectors in physics.
Implement the following four vector operators by completing the code in the next cell in the begin
block:
$$v = \begin{pmatrix} ct \\ x \\ y \\ z \end{pmatrix}$$
$$u = \begin{pmatrix} ct' \\ x' \\ y' \\ z' \end{pmatrix}$$
$$v + u = \begin{pmatrix} ct + ct' \\ x + x' \\ y + y' \\ z + z' \end{pmatrix}$$
$$-v = \begin{pmatrix} -ct \\ -x \\ -y \\ -z \end{pmatrix}$$
$$v - u = \begin{pmatrix} ct - ct' \\ x - x' \\ y - y' \\ z - z' \end{pmatrix}$$
$$v * u = ct * ct' - x * x' - y * y' - z * z'$$
$$|v|^2 = (ct)^2 - x^2 - y^2 - z^2$$
You should implement $|v|^2$ as a function called length_squared
.
+ (generic function with 190 methods)
After defining everything above successfully, the cells below would not give you any error.
MethodError: no method matching Main.var"workspace#2".FourVector(::Float64, ::Float64, ::Float64, ::Float64)
Here is what happened, the most recent locations are first:
MethodError: no method matching Main.var"workspace#2".FourVector(::Float64, ::Float64, ::Float64, ::Float64)
Here is what happened, the most recent locations are first:
UndefVarError: `v` not defined
Here is what happened, the most recent locations are first:
UndefVarError: `v` not defined
Here is what happened, the most recent locations are first:
UndefVarError: `v` not defined
Here is what happened, the most recent locations are first:
UndefVarError: `v` not defined
Here is what happened, the most recent locations are first:
UndefVarError: `v` not defined
Here is what happened, the most recent locations are first:
UndefVarError: `v` not defined
Here is what happened, the most recent locations are first:
UndefVarError: `length_squared` not defined
Here is what happened, the most recent locations are first:
Chess matrices
Implement a function that takes an integer n
as an argument and returns a n × n
matrix with a chess pattern using 1
and 0
.
The matrix elements have to be integers.
Example:
$$n = 3 \rightarrow \begin{pmatrix} 0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0 \\ \end{pmatrix}$$
If you want to have more fun, implement the function again, but this time with the emojis ⬜️ and ⬛️ instead of 0 and 1 😹
Parsing Pauli matrices
In the directory resources
, there are three files:
Matrix_1.txt
Matrix_2.txt
Matrix_3.txt
These are the pauli matrices.
Implement a function that parses these three files and returns the three matrices.
Verify that for all matrices the trace is 0 and the determinant is -1.
Hints:
You don't need
CSV
orDataFrames
!Instead of
lines = open(FILEPATH, "r") do io
return readlines(io)
end
you can just use this shortcut:
lines = readlines(FILEPATH)
You should use
parse(Complex{Float64}, STRING)
for parsing a complex number with real and imaginary parts of type Float64
.
You should use
zeros(Complex{Float64}, (2, 2))
to generate a 2 × 2
matrix with complex numbers with real and imaginary parts as 0 with type Float64
.
The package
LinearAlgebra.jl
might be helpful.