Skip to content

Instantly share code, notes, and snippets.

View IlievskiV's full-sized avatar
🐻‍❄️

Vladimir Ilievski IlievskiV

🐻‍❄️
View GitHub Profile
@IlievskiV
IlievskiV / riemann_stieltjes_integration.py
Created October 2, 2020 10:48
Implementation of the Riemann-Stieltjes Integration in Python
def derivative(f, a, h=0.01):
'''Approximates the derivative of the function f in a
:param function f: function to differentiate
:param float a: the point of differentiation
:param float h: step size
:return float: the derivative of f in a
'''
return (f(a + h) - f(a - h))/(2*h)
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
x_start, y_start = -2, -2 # an interesting region starts here
width, height = 4, 4 # for 4 units up and right
density_per_unit = 200 # how many pixles per unit
# real and imaginary axis
re = np.linspace(x_start, x_start + width, width * density_per_unit )
@IlievskiV
IlievskiV / julia_set.py
Created September 6, 2020 10:08
Implementation of the Julia Set convergence
def julia_quadratic(zx, zy, cx, cy, threshold):
"""Calculates whether the number z[0] = zx + i*zy with a constant c = x + i*y
belongs to the Julia set. In order to belong, the sequence
z[i + 1] = z[i]**2 + c, must not diverge after 'threshold' number of steps.
The sequence diverges if the absolute value of z[i+1] is greater than 4.
:param float zx: the x component of z[0]
:param float zy: the y component of z[0]
:param float cx: the x component of the constant c
:param float cy: the y component of the constant c
@IlievskiV
IlievskiV / animate_mandelbrot_set.py
Created September 6, 2020 10:02
How to animate the convergence of the Mandelbrot set in one interesting lattice of the complex plane
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
x_start, y_start = -2, -1.5 # an interesting region starts here
width, height = 3, 3 # for 3 units up and right
density_per_unit = 250 # how many pixles per unit
# real and imaginary axis
re = np.linspace(x_start, x_start + width, width * density_per_unit )
def mandelbrot(x, y, threshold):
"""Calculates whether the number c = x + i*y belongs to the
Mandelbrot set. In order to belong, the sequence z[i + 1] = z[i]**2 + c
must not diverge after 'threshold' number of steps. The sequence diverges
if the absolute value of z[i+1] is greater than 4.
:param float x: the x component of the initial complex number
:param float y: the y component of the initial complex number
:param int threshold: the number of iterations to considered it converged
"""
@IlievskiV
IlievskiV / calculate_circle_area.ipynb
Created June 7, 2020 23:52
How to numerically calculate the area of a circle
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@IlievskiV
IlievskiV / reflection_principle_bm.ipynb
Created June 5, 2020 21:22
Demonstration of the reflection principle of the Brownian Motion
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@IlievskiV
IlievskiV / pi_geometric_approx_quarter.ipynb
Created June 5, 2020 21:06
Approximating Pi using Monte Carlo Method
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def calculate_integral(f, a, b, n):
'''Calculates the integral based on the composite trapezoidal rule
relying on the Riemann Sums.
:param function f: the integrand function
:param int a: lower bound of the integral
:param int b: upper bound of theintergal
:param int n: number of trapezoids of equal width
:return float: the integral of the function f between a and b
'''
import numpy as np
def gbm_mean(G0, mu, sigma, N, T):
"""Simulates the mean of the Geometric Brownian Motion, which is:
E(t) = G0*e^{(mu + sigma^{2}/2)*t}
:param float G0: initial value
:param float mu: drift coefficient
:param float sigma: diffusion coefficient
:param int N: number of discrete steps
:param int T: number of continuous time steps