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 [9]:
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:
<Figure size 432x288 with 1 Axes>