Skip to content

Instantly share code, notes, and snippets.

@santiago-salas-v
santiago-salas-v / wake_sleep_from_event_log.py
Last active October 7, 2019 11:52
on-off time from win event log
import win32evtlog
import win32evtlogutil
import win32con
import winerror
import time
import sys
import traceback
from os.path import exists
from pandas import read_csv
from matplotlib import pyplot as plt
@santiago-salas-v
santiago-salas-v / log_extrapolate.py
Last active September 23, 2019 18:47
logarithmic extrapolation
from matplotlib import pyplot as plt
from numpy.random import random
from numpy import linspace, log
%matplotlib inline
x = linspace(0.01, 2, 40)
rand_list = (random(len(x))-0.5)
y = log(x-1e-3) + rand_list
y2 = log(x+1e-2*8) + rand_list
x_mid, y_mid = x[int(len(x)/2)], y[int(len(x)/2)]
x_low, y_low = x[3], y[3]
@santiago-salas-v
santiago-salas-v / secant_backtrack.py
Last active September 9, 2019 10:30
backtracking secant method based on: Jr., J. E. Dennis ; Schnabel, Robert B.: Numerical Methods for Unconstrained Optimization and Nonlinear Equations. Philadelphia: SIAM, 1996.
import matplotlib.pyplot as plt
from numpy import finfo, array, sqrt
def y(x):
return x**3 + 4 * x**2 - 10
max_it = 100
tol = finfo(float).eps
alpha = 1e-4
y_list = []
@santiago-salas-v
santiago-salas-v / 3psecant.py
Last active September 9, 2019 14:52
added backtracking to: TIRUNEH, Ababu Teklemariam. A modified three-point Secant method with improved rate and characteristics of convergence. arXiv preprint arXiv:1902.09058, 2019.
import matplotlib.pyplot as plt
from matplotlib import patches
from matplotlib.collections import LineCollection
from numpy import finfo, array, sqrt, isnan, concatenate, sin, exp
def secant_ls_3p(y, x_0, tol, max_it=100):
x_k = x_0
y_k = y(x_k)
g_k = 1 / 2 * y_k**2
@santiago-salas-v
santiago-salas-v / poly_n.py
Last active June 22, 2023 11:29
Laguerre method python implementation
from numpy import array, exp, real, imag, empty, finfo
# Ref. Press, William H., et al. "Numerical recipes in C++." The art of scientific computing 2 (2007): 1002.
def zroots(a, polish=False):
eps = 1.0e-14 # a small number
m = len(a)-1
roots = empty(len(a)-1, dtype=complex)
# copy coefficients for successful deflation
ad = a.copy()
@santiago-salas-v
santiago-salas-v / roots.poly.h
Last active October 7, 2023 06:38
Laguerre polynomial roots
#include<complex>
#include<vector>
#include<limits>
using namespace std;
typedef complex<double> Complex;
//typedef const vector<complex<double>> VecComplex_I;
typedef vector<complex<double>> VecComplex_I;
typedef vector<complex<double>> VecComplex, VecComplex_O;
@santiago-salas-v
santiago-salas-v / permeability_of_polymer_film
Created April 24, 2019 20:10
Permeability of a polymer film
from numpy import array, ones
from numpy.linalg import inv
import matplotlib.pyplot as plt
# Ref. E. L Cussler - Diffusion mass transfer in fluid systems 2009
m = array([14])
text_data = """
0 14.0153
@santiago-salas-v
santiago-salas-v / poly_3_4.py
Last active May 6, 2019 13:26
solve cubic and quartic polynomial - Tartaglia-Cardano-Ferrari
from numpy import array, lexsort, pi, cos, arccos, log10, complex
def solve_cubic(abcd):
""" solve cubic polynomial - Tartaglia-Cardano
ref. Polyanin, Manzhirov Handbook of Mathematics for engineers
and scientists
a*x^3+b*x^2+c*x+d=0
@santiago-salas-v
santiago-salas-v / ttp_01.ipynb
Last active April 22, 2019 02:51
Diffusion
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@santiago-salas-v
santiago-salas-v / ttp_01.py
Last active April 10, 2019 17:08
1) Oberflächenreaktion A+2B==>>2P 2) Oberflächenreaktion A+3B==>> P 3) Freie Ausströmung
from numpy import array, linspace, exp, zeros, diff
from scipy.integrate import odeint, ode
from matplotlib import pyplot as plt
import ctypes # Needed to set the app icon correctly
r1, r2, r3 = [0.33, 1, -0.33]
d21 = d12 = d23 = d32 = 1e-5 # m^2/s
d13 = d31 = 1/10 * d12
y0 = [0.3, 0.7, 0]