Poor conditioning in polynomial interpolation

Here are some points that we could consider to be observations of an unknown function on \([-1,1]\).

using FundamentalsNumericalComputation
n = 5
t = LinRange(-1,1,n+1)
y = @. t^2 + t + 0.05*sin(20*t)


The polynomial interpolant, as computed using polyfit, looks very sensible. It’s the kind of function you’d take home to meet your parents.

p = fit(t,y,n)     # interpolating polynomial

But now consider a different set of points generated in almost exactly the same way.

n = 18
t = LinRange(-1,1,n+1)
y = @. t^2 + t + 0.05*sin(20*t)


The points themselves are unremarkable. But take a look at what happens to the polynomial interpolant.

p = fit(t,y,n)
x = LinRange(-1,1,1000)  # use a lot of points

Surely there must be functions that are more intuitively representative of those points!