Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In the help page ref/message/FunctionInterpolation/ncvb, it is mentioned that one should specify AccuracyGoal for some (even very simple) functions:

FunctionInterpolation[Sqrt[x], {x, 0, 1}, AccuracyGoal -> 2]

However, when I evaluate it, a lot of error messages are generated, such as

Thread::tdlen: Objects of unequal length in {-(1/8),-(1/24),1/24,1/8}^{} cannot be combined. FunctionInterpolation::nreal: "Near x = 1/8, the function did not evaluate to a real number.

Also, the precision I got is very bad (as one can check using Plot[%[x] - Sqrt[x], {x, 0, 1}, PlotRange -> All]). The error is about 5% so not usable for realistic work (and the situation does not change when I increase AccuracyGoal).

Is it a bug? Perhaps I have to do Interpolation or ListInterpolation by hand myself.

$Version

"9.0 for Linux x86 (64-bit) (February 7, 2013)"

PS: I found this thread may be related but still different FunctionInterpolation Errors / Question re Evaluation Order and Options

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Change to real numbers:

fi = FunctionInterpolation[Sqrt[x], {x, 0., 1.}]

Plot[fi@x, {x, 0., 1.}]

enter image description here

The "error" is very small:

Plot[fi@x - Sqrt@x, {x, 0., 1.}]

enter image description here

share|improve this answer
    
Thanks! It's a nice workaround. But considering the integer argument appears in Mathematica's official documentation (also the error messages are not relevant), perhaps I should mark this question as a bug? –  Yi Wang Jun 21 at 15:24
    
@YiWang - Using {0, 1} causes a relatively large pertubation near 0, wheras 0. behaves much better near 0. Yes, maybe it's a bug since Sqrt[0] == 0 and not something near 0. –  eldo Jun 21 at 15:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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