Skip to content

Instantly share code, notes, and snippets.

@rafael-fuente
rafael-fuente / spin_matrices.py
Last active July 5, 2021 12:04
Python script containing the functions to create the spin matrices of a particle with an arbitrary spin s
from sympy.physics.quantum import TensorProduct
import sympy as sp
ħ,θ,φ = sp.symbols("ħ,θ,φ", real=True)
def Splus_matrix(s = sp.Rational(1,2)):
Splus = sp.zeros(2*s+1, 2*s+1)
for j in range(1, 2*s+1):
m = s-j
Splus[j-1,j] = ħ*sp.sqrt(s*(s+1) - m*m -m)
@rafael-fuente
rafael-fuente / spherical_well.py
Created June 24, 2021 12:59
Quantum Eigenstates of a Spherical Well
# The example requires qmsolve package: https://github.com/quantum-visualizations/qmsolve
import numpy as np
from qmsolve import Hamiltonian, SingleParticle, init_visualization
#interaction potential
def sperical_well(particle):
a = 5
r = np.sqrt((particle.x)**2 + (particle.y)**2 + (particle.z)**2)
@rafael-fuente
rafael-fuente / bisection_method.py
Created October 23, 2020 12:06
Bisection method for finding the roots of an equation spicified in func
import numpy as np
def get_all_roots_from_interval(func, extent,N):
roots = []
x = np.linspace(extent[0],extent[1], N)
for i in range(len(x)-1):
if func(x[i])*func(x[i+1]) <= 0:
bisection(x[i],x[i+1], roots,func)
return roots
@rafael-fuente
rafael-fuente / Damped_Double_Pendulum_Simulation.py
Last active December 11, 2024 22:36
Damped Double Pendulum Simulation
#=======================================================================================================================================
# This script computes the equation of motion of a damped double pendulum using a full Newtonian analysis with sympy,
# then solve them numerically, and finally visualize the solution using matplotlib.
#=======================================================================================================================================
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt