3
$\begingroup$

Is there a way to specify the grid spacing for interpolation?

For example I would like the values of a to change in step of 0.34. How can I write this step in the FunctionInterpolation?

f = FunctionInterpolation[NIntegrate[-a*(x - 5)^2 - 3 Sqrt[y] + Cos[x], {x, 0, 10}, {y, 0, 3}], {a, 0, 3}]

And what is default step Mathematica uses?

$\endgroup$
2
  • $\begingroup$ Not an answer but I always used Interpolation and made the list using Table. $\endgroup$ Oct 1, 2022 at 16:31
  • $\begingroup$ is it impossible to do for FunctionInterpolation? $\endgroup$
    – Mam Mam
    Oct 1, 2022 at 16:49

1 Answer 1

3
$\begingroup$
$Version

(* "13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)" *)

Clear["Global`*"]

f[a_?NumericQ] := 
 NIntegrate[-a*(x - 5)^2 - 3 Sqrt[y] + Cos[x], {x, 0, 10}, {y, 0, 3}]

You can specify the step size using the standard form for an iterator.

fi = FunctionInterpolation[f[a], {a, 0, 3, 0.34}]

enter image description here

However, the iterator stops at 2.72 and the upper portion of the interval {0, 3} then requires extrapolation.

fi[2.9]

(* bInterpolatingFunction::dmval: Input value {2.9} lies outside the range of data in the interpolating function. Extrapolation will be used. *)

(* -830.555 *)

Plot[{f[a], fi[a]}, {a, 0, 3},
 PlotStyle -> {Automatic, Dashed},
 PlotLegends ->
  Placed["Expressions", {.8, .65}]]

enter image description here

$\endgroup$
7
  • $\begingroup$ When I write this line fi = FunctionInterpolation[f[a], {a, 0, 3, 0.34}] Mathematica highlights step (this part , 0.34) in red, like a mistake in syntax. $\endgroup$
    – Mam Mam
    Oct 1, 2022 at 18:26
  • $\begingroup$ Does the code execute as expected despite the red color? If not, what version are you running and on what OS? $\endgroup$
    – Bob Hanlon
    Oct 1, 2022 at 18:49
  • $\begingroup$ I'm running Mathematica 12.0 on Windows 10. But surprisingly it executes correctly. Is it possible to change it? $\endgroup$
    – Mam Mam
    Oct 1, 2022 at 20:27
  • $\begingroup$ I'm confused. If it executes correctly, what do you want to change? $\endgroup$
    – Bob Hanlon
    Oct 1, 2022 at 22:23
  • $\begingroup$ It's just weird to see some red code. $\endgroup$
    – Mam Mam
    Oct 1, 2022 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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