Message Boards Message Boards

0
|
8272 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Spline method for interpolation doesn't seem to be working

Posted 9 years ago

So I was trying to show the difference between a polynomial interpolation and a spline interpolation for an assignment and I wrote the below code.

f[x_] := 1/(1 + 25 x^2)
data[n_] := Table[{x, f[x]}, {x, -1, 1, 2/n}];
polyinterpolate[order_, n_] := LinearModelFit[data[n], Table[X^i, {i, 1, order, 1}], X]
cubicspline[order_, n_] := Interpolation[data[n], Method -> "Spline", InterpolationOrder -> order]

"f" is the function I want to fit to in the domain -1 to 1, "data" creates a table of n evenly spaced points on the function. "polyinterpolate" fits the points to a polynomial of order o. "cubicspline" interpolates using the spline method to order o.

I'm not sure what is wrong with my code but polyinterpolate and cubicspline give the same fits to any n points. Could InterpolationOrder be overriding Method-> in some way?

Thanks!

POSTED BY: Jack Madden
2 Replies
Posted 9 years ago

Hello I have the same OK result with Version 10.0 for Microsoft Windows (64-bit). We do not know with what version the problem arises.

POSTED BY: wojtek potocki
Posted 9 years ago

Hello,

I run your code in M10.1 and it seems to work. Below I attached a screen shot so you can see the plots. I plotted on top the function and the two simulations and below the diffs. Spline based simulation is very close to f[x], so in the top plot only two curves can be distinguished.

Screenshot from my M10.1 Notebook

POSTED BY: Michael Helmle
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract