# Most Accurate/Efficient Interpolation approach for 1D/2D, discrete-continuous hybrid problem

**URL:** <https://discourse.julialang.org/t/most-accurate-efficient-interpolation-approach-for-1d-2d-discrete-continuous-hybrid-problem/48515>\
**Category:** Numerics\
**Created:** [October 16, 2020, 7:57pm UTC](https://discourse.julialang.org/t/most-accurate-efficient-interpolation-approach-for-1d-2d-discrete-continuous-hybrid-problem/48515 "2020-10-16T19:57:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [October 16, 2020, 7:57pm UTC](https://discourse.julialang.org/t/most-accurate-efficient-interpolation-approach-for-1d-2d-discrete-continuous-hybrid-problem/48515/1 "2020-10-16T19:57:37Z")

</div>

Hi all, looking for advice on the best way to get very accurate results in finite computing time, for this problem:

A discrete grid in `x`, with `f(x)` values at each point. For any initial choice of `x0`, need to interpolate `f(x)` in the neighboring area, do a bunch of calculations on `f(x)` to get new function `f2(x)` in this neighborhood, then find where the local minimum of `f2(x)` is.  
(The problem has to stay as continuous as possible, since the minimum place for `f2`, at `xMin`, does NOT have to be at one of the discrete data locations, but should be found as precisely as possible.)

But, this is actually a 2D problem, in time `t` and position `x`. Because after it calculates that `xMin`, it steps to `xMin` and ahead to the next time value, and then begins the process all over again for the next timestep: it finds the next `xMin` for the new `t`, and continues stepping again and again unless it gets to the end time. (At almost all times, the stepper will be located in between the actual discrete `x` data points, not exactly on one of them.)

Also, the problem is also somewhat continuous in t, because the whole 2D function I’m starting with is really obtained as a numerical solution to a partial differential equation using the Method of Lines. So, at each `x` point, what I really have isn’t just a single data point, but is an ODE interpolation solution `x(t)`, so it is continuous in time (sort of). So, maybe there is a more holistic interpolation approach that can do the whole 2D interpolation in `(t,x)` at once, for the neighborhood around the place where the stepper is located at the moment.

This problem is complicated, so I’d appreciate any advice on either the simpler problem (for a single value of `t`) – discrete data points, interpolation, calculations with the interpolation, continuous minimum finding – or on the whole 2D problem (if possible).

Thanks!

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [October 16, 2020, 8:02pm UTC](https://discourse.julialang.org/t/most-accurate-efficient-interpolation-approach-for-1d-2d-discrete-continuous-hybrid-problem/48515/2 "2020-10-16T20:02:14Z")

</div>

BTW, I’ve heard of ApproxFun for approximating a whole data set, but I’m not sure if that’s the best choice here, because I’m only interpolating a few (~10-20) `f(x)` data points in the neighborhood of my `x` for the stepper, not the function at all `x` everywhere.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 18, 2020, 12:07pm UTC](https://discourse.julialang.org/t/most-accurate-efficient-interpolation-approach-for-1d-2d-discrete-continuous-hybrid-problem/48515/3 "2020-10-18T12:07:15Z")

</div>

> [@CosmoProf](#):
>
> the best way to get very accurate results in finite computing time, for this problem

Your question is underspecified: a lot depends on the properties of your function.

> [@CosmoProf](#):
>
> maybe there is a more holistic interpolation approach that can do the whole 2D interpolation in `(t,x)` at once

I am not sure I fully understand the question, but a simple tensored spectral (eg Chebyshev polynomial) approach may work with sufficiently smooth/differentiable functions. As always, I would recommend

> **[Boyd.pdf](https://depts.washington.edu/ph506/Boyd.pdf)**

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 18, 2020, 6:30pm UTC](https://discourse.julialang.org/t/most-accurate-efficient-interpolation-approach-for-1d-2d-discrete-continuous-hybrid-problem/48515/4 "2020-10-18T18:30:56Z")

</div>

> [@CosmoProf](#):
>
> maybe there is a more holistic interpolation approach that can do the whole 2D interpolation in `(t,x)` at once

A physics-informed neural network or a tensor product of 1D universal approximators as Tamas mentions.

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [October 18, 2020, 7:14pm UTC](https://discourse.julialang.org/t/most-accurate-efficient-interpolation-approach-for-1d-2d-discrete-continuous-hybrid-problem/48515/5 "2020-10-18T19:14:13Z")

</div>

Thanks for the links & references guys, I’ll check it out.

For now, to develop some procedures, I’m just working with the plain wave equation:  
`ftt = fxx`.  
(That is, `d^2/dt^2 {f(t,x)} = d^2/dx^2 {f(t,x)}` .)

I guess what I was more specifically asking with my question, is whether Julia has a 2-dimensional version of a “spline”-like interpolator. Preferably where it can handle discrete data in one dimension (`x`), and 1D interpolation data (coming from ODE integrators) in the other diimension (`t`). Or, at least, a 2D interpolation that can handle discrete data in both dimensions (`t,x`).
