Message Boards Message Boards

0
|
4258 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Why am I getting Interpolation::mspl from this code?

Posted 11 years ago

I'm getting an unexpected error message from the following code. I'm trying to interpolate a function, defining the function value and its derivative.

ys6 = RandomReal[NormalDistribution[], 20]
dys6 = Join[
  {0.0},
  (ys6[[3 ;; -1]] - ys6[[1 ;; -3]])/2,
  {0.0}
  ]
ydata6 = Transpose@{Table[{x}, {x, 20}], ys6, dys6}
sf2 = Interpolation[ydata6, Method -> "Spline"]

At this point I get the error Interpolation::mspl: "The Spline method could not be used because the data could not be coerced to machine real numbers". What does this mean? What data can't be coerced to real?

The following:

hf1 = Interpolation[ydata6, Method -> "Hermite"]

...works without error and produces the expected result. In fact, despite producing an error message, the "Spline" method also returns an InterpolatingFunction, which plotting shows to be superimposable with hf1.

(Mathematica 10, MacOS. Attached notebook has complete example.)

Attachments:
POSTED BY: Leon Avery
3 Replies

The message is somewhat misleading. It is correct only up to "The Spline method could not be used" and in fact the implementation does not currently support derivatives. In such cases, Interpolation falls back on the default method (Hermite) which is why sf2 and hf1 are the same.

POSTED BY: Ilian Gachevski
Posted 11 years ago

Don't think so. That's the way the documentation says to do it, and it doesn't work at all if I don't do it that way. Try it yourself!

POSTED BY: Leon Avery

Your x values are more deeply nested than the ys6 and the dys6. Could that be the reason?

{{{1}, 0.130962, 0.}, {{2}, -0.376878, 0.387584}, ...

POSTED BY: Frank Kampas
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