I’m trying to define a cubic spline as a function in Mathematica 8 as I’ve got every P_{i} (which, of course, are polynomials of degree 3) for each interval [x_{i}, x_{i + 1}], i = 0, ..., n. What I want to do is to define s in the interval [x_{0}, x_{n + 1}] as . How can I do that as s(x) = P_{i}(x) if x is in [x_{i}, x_{i+1}]n varies? I was thinking of Piecewise but that didn’t work.
I’m trying to define a cubic spline as a function in Mathematica 8 as
Share
This does precisely what you ask, if I’m not mistaken. It’s a bit ugly though. There are better alternatives.
If you want to make the result dependent on the current state of the global variable
n(which I wouldn’t advocate) thne you can replace theSet(=) in the definition offwithSetDelayed(:=), but this implies re-evaluating theTablefor every call off. Not that bad for small values of n, but I don’t like it. Results in that case look like this: