Skip to content

Instantly share code, notes, and snippets.

View jwscook's full-sized avatar

James Cook jwscook

View GitHub Profile
@jwscook
jwscook / ComplexDerivatives.jl
Created October 15, 2025 14:03
Complex derivatives in julialang, taking only the first Wirtinger derivative
using ForwardDiff, StaticArrays
function jacobi(f, x)
x_real = @SArray [real(x), imag(x)]
function f_real(v)
z = complex(v[1], v[2])
result = f(z)
return @SArray [real(result), imag(result)]
end
J = ForwardDiff.jacobian(f_real, x_real)
@jwscook
jwscook / QRGivens.jl
Created December 3, 2025 12:33
QR decomposition via Givens rotations
using LinearAlgebra
"Compute Givens rotation parameters to zero out b"
function givens_rotation(a, b)
T = promote_type(typeof(a), typeof(b))
if iszero(b)
return one(T), zero(T)
elseif abs(b) > abs(a)
t = a / b
s = 1 / sqrt(1 + t^2)