import numpy as np
import matplotlib.pyplot as plt
My function: $$f(x; a, b) = exp(-a x^2 - b x^4)$$
This has a value of 1 at x=0 and a derivative of 0 at x=0.
def f(x, a, b):
return np.exp(-a * x**2 - b * x**4)
vectorized_f = np.vectorize(f)
def product(ys_list):
"""Compute the product of multiple functions."""
ys_product = np.ones(xs.size)
for ys in ys_list:
ys_product *= ys
return ys_product
Here I create 160 functions with random a and b parameters, then plot the product of the first n functions for various values of n including 10 as requested in the problem. We see, as expected, that the product of the functions falls faster as n grows.
# Get the y values for several random functions.
NUM_FUNCS = 160
xs = np.linspace(0, 0.6, num=1000)
ys_list = []
for _ in xrange(NUM_FUNCS):
a, b = np.random.randint(1, 20, size=2)
ys_list.append(vectorized_f(xs, a, b))
# Plot each individual function.
for ys in ys_list:
plt.plot(xs, ys, color='lightgray')
# Plot the product of the first n functions for various values of n.
for count in (5, 10, 20, 40, 80, 160):
plt.plot(xs, product(ys_list[:count]), label='product of first {}'.format(count))
plt.legend()
<matplotlib.legend.Legend at 0x9c13f4c>