# How to extrapolate on non-uniform grid?

**URL:** <https://discourse.julialang.org/t/how-to-extrapolate-on-non-uniform-grid/134394>\
**Category:** Numerics\
**Tags:** interpolations\
**Created:** [December 5, 2025, 10:34pm UTC](https://discourse.julialang.org/t/how-to-extrapolate-on-non-uniform-grid/134394 "2025-12-05T22:34:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [December 5, 2025, 10:34pm UTC](https://discourse.julialang.org/t/how-to-extrapolate-on-non-uniform-grid/134394/1 "2025-12-05T22:34:00Z")

</div>

How to interpolate(actually extrapolate later) Bp values on `r`,`θ`and `ϕ` grid? I have non-uniform grid of `r`,`θ`and `ϕ`, where r is geometric series and `θ`and `ϕ` have constant spacing.

```julia-auto
r = Float32[1.677044, 1.8385518, 2.0156136, 2.2097273, 2.4225352, 2.6558375, 2.911608, 3.1920104, 3.499417, 3.8364286, 4.205896, 4.6109447, 5.055002, 5.5418243, 6.0755296, 6.660634, 7.3020864, 8.005314];
θ = Float32[0.049087387, 0.14726216, 0.24543692, 0.3436117] ;
ϕ = Float32[0.19634955, 0.5890486, 0.9817477, 1.3744467, 1.7671459, 2.1598449, 2.552544, 2.9452431, 3.3379421, 3.7306414, 4.12334, 4.5160394, 4.9087386, 5.3014374, 5.6941366, 6.086836];
#= This code prints geometric ratio of r
for i in 2:length(r)-1
   println(r[i]/r[i-1])
end=#
Bp = rand(18, 4, 16)

```

---

<div class="post-metadata">

**Author:** ![JADekker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jadekker/32/210281_2.png) [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Post date:** [December 6, 2025, 7:24am UTC](https://discourse.julialang.org/t/how-to-extrapolate-on-non-uniform-grid/134394/2 "2025-12-06T07:24:31Z")

</div>

If r is geometric, then log r should have constant spacing, so you can do interpolation/extrapolation on a uniform grid using this change of variables.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [December 6, 2025, 9:14pm UTC](https://discourse.julialang.org/t/how-to-extrapolate-on-non-uniform-grid/134394/3 "2025-12-06T21:14:27Z")

</div>

```julia-auto
ext_itp = extrapolate(interpolate((log.(r), θ, ϕ), Bp, Gridded(Linear())), Interpolations.Line());
ext_itp(10, 2,3)
ext_itp = extrapolate(interpolate((r, θ, ϕ), Bp, Gridded(Linear())), Interpolations.Line());
ext_itp(10, 2,3)

```

Yes, `log.(r)` will make it uniform, but it will be extrapolation on different value. Note that i am using **Polar coordinates**. How should i call `ext_itp()` on values?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 7, 2025, 7:03am UTC](https://discourse.julialang.org/t/how-to-extrapolate-on-non-uniform-grid/134394/4 "2025-12-07T07:03:55Z")

</div>

As @JADekker suggested, you can define your extrapolator function (functor) like this:

```julia-auto
using Interpolations
extrapol = linear_interpolation((log.(r), θ, ϕ), Bp, extrapolation_bc=Line())

```

And then evaluate it at any point `r₁, θ₁, ϕ₁` as follows:

```julia-auto
extrapol(log(r₁), θ₁, ϕ₁)

```
