Scratchpad


Reading time: about 4 minutes
In [1]:
get_ipython().ast_node_interactivity = 'all'
import matplotlib.pyplot as plt
import os
import math
import numpy as np
In [2]:
def plot_fn(fn, start, end, step):
    l = [fn(x) for x in np.arange(start, end, step)]
    plt.plot(l)
In [3]:
def real_f(x):
    PI = 3.14159265
    return (1 / math.sqrt(2 * PI)) * math.exp(-0.5 * math.pow(x, 2.0))

plot_fn(real_f, -3, 3, 0.0001)
Out:
<Figure size 432x288 with 1 Axes>
In [1]:
def make_poly_f(params):
    def f(x):
        res = 0
        l = len(params)
        for i, param in enumerate(params):
            res += param * math.pow(x, l - i - 1)
        return res
    return f


params = [-0.001351881896958825, -1.3472626944500271e-06, 0.0258183586346407, 1.1661833394212631e-05, -0.16774103108355934, -1.8935633914021407e-05, 0.39197121674427576]
pf = make_poly_f(params)

plot_fn(real_f, -3, 3, 0.0001)
plot_fn(pf, -3, 3, 0.0001)
Out:
[ERROR] NameError: name 'plot_fn' is not defined
In [21]:
inp = [3, 1, 4, 4, 3, 1, 1]
out = [2, 6, 1, 7, 5, 3, 4]

x = [i for i in range(len(inp))]
y = [0 for _ in inp]

for i, v in enumerate(inp):
    val = x.pop(v - 1)
    y[val] = i + 1

y
Out [21]:
[2, 6, 1, 7, 5, 3, 4]

The following pages link here

Citation

If you find this work useful, please cite it as:
@article{yaltirakliwikiscratchpad,
  title   = "Scratchpad",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2024",
  url     = "https://www.gkbrk.com/wiki/scratchpad/"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Scratchpad", November, 2024. [Online]. Available: https://www.gkbrk.com/wiki/scratchpad/. [Accessed Nov. 12, 2024].
APA Style
Yaltirakli, G. (2024, November 12). Scratchpad. https://www.gkbrk.com/wiki/scratchpad/
Bluebook Style
Gokberk Yaltirakli, Scratchpad, GKBRK.COM (Nov. 12, 2024), https://www.gkbrk.com/wiki/scratchpad/

Comments

© 2024 Gokberk Yaltirakli