#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) beta = 1 / npy.sqrt(2) state = npy.array([alpha, beta]) dt = 0.2 iterations = 200 H = npy.array([[2,-2j],[2j,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]) phi = 2 * npy.arctan(1 / abs(temp)) theta = npy.arctan(temp.imag / temp.real) return npy.array([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", "a") for i in range(iterations): state = time_evolution(state) h = npy.dot(state, state) historie = npy.vstack([historie,bloch_map(state)]) coords = bloch_map(state) coords = sphere2cart(coords[0], coords[1]) #print(f"{coords[0]}; {coords[1]}; {coords[2]}") f.write(f"{coords[0]}; {coords[1]}; {coords[2]}\n") f.close() subprocess.run(["gnuplot", "gnuplot.plt"])