nlsq.core.functions.polynomial¶
- nlsq.core.functions.polynomial(degree)[source]¶
Create polynomial function of given degree.
Returns a function that computes: y = c0*x^n + c1*x^(n-1) + … + cn where n is the degree.
- Parameters:
degree (int) – Polynomial degree (0, 1, 2, 3, …)
- Returns:
poly_func – Polynomial function with signature poly(x, *coeffs)
- Return type:
callable
Examples
>>> from nlsq import curve_fit >>> from nlsq.core.functions import polynomial >>> import numpy as np >>> >>> # Fit quadratic: y = ax² + bx + c >>> quadratic = polynomial(2) >>> x = np.linspace(-5, 5, 50) >>> y = 2*x**2 + 3*x + 1 + np.random.normal(0, 0.5, 50) >>> popt, pcov = curve_fit(quadratic, x, y, p0='auto') >>> print(f"Coefficients: {popt}")