3

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?

Mam Mam
  • 1,843
  • 2
  • 9

1 Answers1

3
$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

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198