🐻❄️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| """ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| ''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |