Skip to content

Instantly share code, notes, and snippets.

View glederrey's full-sized avatar
☠️

Gael Lederrey glederrey

☠️
  • Swiss-SDI
  • Switzerland
View GitHub Profile
@glederrey
glederrey / conjgrad.py
Created May 28, 2018 13:17
Conjugate Gradient in Python
def conjgrad(A, b, x):
"""
A function to solve [A]{x} = {b} linear equation system with the
conjugate gradient method.
More at: http://en.wikipedia.org/wiki/Conjugate_gradient_method
========== Parameters ==========
A : matrix
A real symmetric positive definite matrix.
b : vector
The right hand side (RHS) vector of the system.
@glederrey
glederrey / cfd_grad_hess.py
Created March 28, 2018 14:00
Central Finite Differences for computing Gradient and Hessian
#!/usr/bin/env python
import numpy as np
def gradient(x, func, eps=1e-6):
"""
Central finite differences for computing gradient
INPUT:
x: vector of parameters with shape (n, 1)