5
$\begingroup$

This question already has an answer here:

Both

FunctionInterpolation[1, {x, 0,1.00000000000000004}]

and

FunctionInterpolation[1.00000000000000004, {x, 0, 1}];

give mysterious errors:

Thread::tdlen: Objects of unequal length in {-0.12500000000000000,-0.04166666666666667, 0.04166666666666667,0.12500000000000000}^{} cannot be combined. >>
Thread::tdlen: Objects of unequal length in {-2.0794415416798359+3.1415926535897932 I, -3.1780538303479456+3.1415926535897932 I,-<<58>>,-2.0794415416798359} {} cannot be combined. >>
General::stop: Further output of Thread::tdlen will be suppressed during this calculation. >>
FunctionInterpolation::nreal: Near x = 0.125`17., the function did not evaluate to a real number. >>

Here 1.00000000000000004 has precision 17, which is larger than MachinePrecision ~ 15. Removing a couple of zeros avoids the errors. Manually lowering the precision also works, as this gives no errors:

FunctionInterpolation[1, {x, 0, SetPrecision[1.00000000000000004, MachinePrecision]}]

Increasing PrecisionGoal and AccuracyGoal do nothing, and the option WorkingPrecision is not used.

Finally, note that other functions like Plot[] don't have this problem:

Plot[1, {x, 0,1.00000000000000004}]

works fine.

I'm on 10.3.0.0 on OSX. What's going on?

Please note that I need high-precision output, so ignoring the errors isn't sufficient, nor are the older questions here and here. The behavior of this error makes it difficult to isolate, but here is an example where a fix is needed:

With[{n = 1.001}, Block[{f, A1, B1},
  f = Function[{A}, ArcSin[n* Sin[A]] - A];
  A1 = ArcSin[1/n];
  B1 = f[A1];
  g = FunctionInterpolation[Sin[InverseFunction[f][B]], {B, 0, B1}, MaxRecursion -> 12];
  Plot[g[B], {B, 0, B1}, PlotRange -> Full]
]]

which plots this as expected:

enter image description here

But if we replace n = 1.001 with 1.00000000000000004, which pushes the curve further toward the upper left-hand corner, we get errors which depend on the value of MaxRecursion and other details, or the computation my simply become intractably slow.

$\endgroup$

marked as duplicate by m_goldberg, MarcoB, user9660, Öskå, dr.blochwave May 31 '16 at 9:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ It's actually useful for me to give FunctionInterpolation[] high-precision data, since I need to approximate the function right up to the (high-precision) point that it becomes undefined. $\endgroup$ – Jess Riedel May 28 '16 at 0:26
  • $\begingroup$ Use exact numbers, e.g., FunctionInterpolation[1, Evaluate@{x, 0, 1.00000000000000004 // Rationalize[#, 0] &}] and FunctionInterpolation[Evaluate@Rationalize[1.00000000000000004, 0], {x, 0, 1}] Although there are no errors without the use of Evaluate, I include its use since FunctionInterpolation has attribute HoldAll $\endgroup$ – Bob Hanlon May 28 '16 at 1:06
  • $\begingroup$ Will FunctionInterpolation use high-precision internally, or this equivalent to using SetPrecision[1.00000000000000004,MachinePrecision]? What's going on with this anyways? $\endgroup$ – Jess Riedel May 28 '16 at 1:13
  • 6
    $\begingroup$ Related?: (51224) $\endgroup$ – Mr.Wizard May 28 '16 at 1:45
  • 2
    $\begingroup$ FWIW, this sort of problem has led me to avoid FunctionInterpolation (even when I shouldn't). I sometimes use NDSolve to construct an interpolation, either from an ODE or a DAE. $\endgroup$ – Michael E2 May 28 '16 at 6:59
4
$\begingroup$

This is an irritating bug that was introduced in V8 and has not been fixed even in the latest version (10.4.1) of Mathematica.

Both

f = FunctionInterpolation[N[1, 20] x, {x, 0, 1}]

and

g = FunctionInterpolation[N[1, 2] x, {x, 0, 1}]

give a spate of error messages similar to ones you encountered. In both cases the functions returned appear to behave normally. For example, both Plot[f[x], {x, 0, 1}] and Plot[g[x], {x, 0, 1}] produce a plot that looks like

plot

$\endgroup$
  • $\begingroup$ Thanks, upvoted. Unfortunately this isn't sufficient, as I've edited my question to try and explain. $\endgroup$ – Jess Riedel May 28 '16 at 4:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.