#import plotting import subprocess import math as mth import cmath as cmt import numpy as npy import scipy.linalg as sla #alpha = 1 / npy.sqrt(2) alpha = 1 #beta = 1 / npy.sqrt(2) beta = 1 norm = npy.linalg.norm([alpha, beta]) state = npy.array([alpha / norm, beta / norm]) dt = 0.1 iterations = 61 H = npy.array([[2,0],[0,3]]) def time_evolution(state, dt = dt): return npy.dot(state, sla.expm(-1j * dt * H)) def bloch_map(state): temp = npy.conj(state[0] / state[1]) theta = 2 * npy.arctan(abs(temp)) phi = cmt.phase(temp) return (phi, theta) def sphere2cart(phi, theta): return [ mth.sin(theta) * mth.cos(phi), mth.sin(theta) * mth.sin(phi), mth.cos(theta) ] historie = npy.array([bloch_map(state)]) f = open("data", "w") for i in range(iterations): state = time_evolution(state) h = npy.dot(state, state) historie = npy.vstack([historie,bloch_map(state)]) (phi, theta) = bloch_map(state) coords = sphere2cart(phi, theta) f.write(f"{coords[0]}; {coords[1]}; {coords[2]}; {(i + 1) / iterations}\n") f.close() subprocess.run(["gnuplot", "gnuplot.plt"])