0

I successfully imported some optical data to Mathematica, which I need to interpolate to use it as a proper function. The command data=Interpolation[] was quite helpful, but know I'm in doubt whether it is the best way to define a function f[x_]:=data[x] when the function will later be called upon in a numerical integration with NIntegrate[].

What is the best way to store the interpolated data in terms of computational time when using it later in NIntegrate[]? Any advice is highly appreciated.

Thank you!

NeverMind
  • 1,201
  • 7
  • 9
  • There's no reason you can't NIntegrate[] an InterpolationFunction – Feyre Aug 09 '16 at 15:12
  • Yes, but compared to a non-interpolated function it takes much more computational time. That's the reason why I was wondering whether there is a more efficient way to store the interpolated values. – NeverMind Aug 09 '16 at 15:15
  • I don't think that's true, at least not when you always use NIntegrate[] – Feyre Aug 09 '16 at 15:18
  • Ok, so if there is no other way that is more efficient I have to stick to this method and see how I can otherwise improve my code. – NeverMind Aug 09 '16 at 15:19
  • Actually let me amend that, it seems to depend on the exact data used. I guess you can try to FindFit[] instead? – Feyre Aug 09 '16 at 15:23
  • …are the data noisy, or are they exact? (Interpolate in the first case, and fit in the second case.) – J. M.'s missing motivation Aug 09 '16 at 15:24
  • Unfortunately, they are pretty noisy with various peaks. Don't think you could find a proper fit. Interpolation should be right here. – NeverMind Aug 09 '16 at 15:30
  • 1
    Note that you can Integrate an InterpolatingFunction, since it is a piecewise-polynomial function and therefore easy to piecewise-integrate. (I learned that here somewhere.) – march Aug 09 '16 at 15:36
  • @march +1! Interesting, that makes it faster than Integrating even regular functions. – Feyre Aug 09 '16 at 15:43
  • @Feyre. The issue I've run into, of course, is that you can only do Integrate[func[x], {x, ...}], where func is the InterpolatingFunction. As soon as you do e.g. Integrate[x^2 func[x], {x, ...}], it fails to integrate, even though one would hope that Mathematica would recognize that x^2*func[x] is still piecewise-polynomial. – march Aug 09 '16 at 15:45
  • "pretty noisy with various peaks" - then interpolation is apparently not what you want, unless you want a function that faithfully reproduces those "noisy peaks". – J. M.'s missing motivation Aug 09 '16 at 18:29
  • Maybe "pretty noisy" was the wrong expression. I mean it's detailed data of a typical dieletric function of a material with certain peaks, but not completely messed up. I looked at the interpolated curves and they look pretty nice, but the integration time afterwards take a lot of time, unfortunately. – NeverMind Aug 09 '16 at 22:31

0 Answers0