# piecewise polynomial least squares fit

I have in mind a project involving a least-squares fit using piecewise polynomials; at a finite number of known arguments $x_j$, the $k_j$th derivative is discontinuous.

How many basis functions are needed? My guess is: $x^n$ for 0≤n<min(k), and then, for each j, for each n such that $k_j \le n \le p$ (for some p), a pair of functions which are zero on one side and $(x-x_j)^n$ on the other. Is that right?

In general, I welcome any pointers that might reduce the number of wheels I'll reinvent.

(Why is there no “piecewise” tag?)

Update: Results.

## 1 Answer

Got a satisfying answer on Wikipedia Reference Desk from Meni Rosenfeld:

“If the function is on the domain $[x_0,x_m]$, and the polynomials are of degree at most $d$, and for $1\le j<m$ the derivatives at $x_j$ are expected to be continuous up to $k_j-1$ ($k_j$ constraints), then I'm pretty sure the number of degrees of freedom is $m(d+1)-\sum_{j=1}^{m-1}k_j$.

“And I think the following basis functions will work (probably the same as what you wrote, but I think is clearer): Letting $k_0=0$, for each $0 \le j < m$ and $k_j \le n \le d$, the function which is 0 for $x \le x_j$ and $(x-x_j)^n$ for $x>x_j$. This also means their number can be rewritten as $\sum_{j=0}^{m-1}(d+1-k_j)$.”