Skip to content

Instantly share code, notes, and snippets.

View dermesser's full-sized avatar
🐢
a bit of time :-)

Lewin Bormann dermesser

🐢
a bit of time :-)
View GitHub Profile
@dermesser
dermesser / linear_box_phasespace.py
Last active December 2, 2020 17:53
RWTH Theoretische Physik IV WS 20/21 ÜB 5 A2 a). Outputs to MP4. (https://youtu.be/2pKO514cMNU)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 1 12:12:22 2020
Run: $ python a2a.py
Writes to `animation.mp4`. Adjust parameters below.
@author: lbo
"""
@dermesser
dermesser / harmonic_oscillator_phasespace_animate.py
Last active December 2, 2020 17:53
Animating phase space movement in a 1D harmonic oscillator: https://youtu.be/v4edySA8Gzk (contains numeric friction)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 1 12:12:22 2020
@author: lbo
"""
import numpy as np
import matplotlib.pyplot as plt
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 1 12:12:22 2020
@author: lbo
"""
import numpy as np
import matplotlib.pyplot as plt
@dermesser
dermesser / simplesexpr.py
Created December 10, 2020 13:27
A naive S-expr parser in python
#!/usr/bin/env python3
# Simple sexpr parser
from collections import namedtuple
Expr = namedtuple('Expr', ('children'));
OPEN = 1
CLOSE = 2
@dermesser
dermesser / mlmagic.cc
Last active January 14, 2021 21:33
Use a Kernel Ridge Regression to classify Pion vs. Proton events in a (fictional?) detector.
/*
* To run, install BLAS, LAPACK, and DLib, then do this:
*
* $ g++ -l:libcblas.so.3 -l:liblapack.so.3 -ldlib mlmagic.cc -o run && ./run
*
* If it doesn't work, fiddle with the -l options and ensure that you have the right libraries installed.
*
* This file is very very roughly modeled after the DLib example for Kernel Ridge Regression:
* http://dlib.net/krr_classification_ex.cpp.html
*/
@dermesser
dermesser / radon.py
Created March 16, 2021 09:46
Radon transform: Sampling and reconstruction
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 13 19:26:59 2021
@author: lbo
"""
import numpy as np
from numpy import fft
@dermesser
dermesser / linreg.jl
Created March 16, 2021 10:43
Some handy utilities for calculating and drawing linear regressions in Julia, including residual analysis.
import LsqFit
import Plots
function fwhm(sigma::Real)::Float64
# Calculate FWHM from sigma.
2sqrt(2log(2))*sigma
end
const M64 = Measurements.Measurement{Float64}
@dermesser
dermesser / STM.jl
Last active April 2, 2021 21:32
Simulation of a Scanning Tunneling Microscope's control algorithm (Pluto notebook)
### A Pluto.jl notebook ###
# v0.12.21
# (c) 2021 Lewin Bormann
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
@dermesser
dermesser / sinfit.jl
Created March 31, 2021 12:08
Quite accurately estimate the four wave parameters for a (co)sine wave, using some simple statistics and FFT.
using DataFrames
import FFTW
import Statistics
"""
estimate_wave_params(df::DataFrame, xsym::Symbol, ysym::Symbol)
Use Fourier analysis and statistics to find the best monochromatic sine wave parameters for data.
`xsym` and `ysym` are the column symbols for the x and y columns within DataFrame `df`, respectively.
@dermesser
dermesser / kirchhoff.jl
Last active May 23, 2021 11:53
Calculate Kirchhoff-Fresnel diffraction integrals with visualization. Explanation: https://lewinb.net/posts/diffraction/ - example: http://borgac.net/~lbo/doc/kirchhoff.pdf
### A Pluto.jl notebook ###
# v0.14.3
using Markdown
using InteractiveUtils
# ╔═╡ 6d796395-5024-4129-a250-df2401327711
using Setfield
# ╔═╡ 87c80fda-9eda-11eb-2ac5-b7b5006b19b7