Is there an easy way to get a solution where there is a constraint on the maximum value of a derivative of a polynomial function f(x), for a certain range of values for x?
Like was answered to this question, curve_fit from scipy.optimize can deal with constraints on the individual coefficients, like in the following example:
def func(x, a, b, c, d):
return a + b * x + c * x ** 2 + d * x ** 3
x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0])
popt_cons, _ = curve_fit(func, x, y, bounds=([-np.inf, 2, -np.inf, -np.inf], [np.inf, 2.001, np.inf, np.inf]))
print(popt_cons)
>>> [-0.14331349 2. -0.95913556 0.10494372]
But what if I wanted the best fit polynomial where there is a constraint on for example the maximum value of the acceleration (second derivative) for a certain range of x values?
That means, by integrating the function twice, that there is a constraint on the value of 2*c + 6*d*x for lets say, x between 0 to 10.
Is there a method to do this, or do I have to build this from scratch?