# Multi Dimension Interpolation with Unitful

**URL:** <https://discourse.julialang.org/t/multi-dimension-interpolation-with-unitful/129043>\
**Category:** General Usage\
**Tags:** interpolations, unitful\
**Created:** [May 15, 2025, 3:45pm UTC](https://discourse.julialang.org/t/multi-dimension-interpolation-with-unitful/129043 "2025-05-15T15:45:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luke-pikaart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luke-pikaart/32/29361_2.png) [@luke-pikaart](https://discourse.julialang.org/u/luke-pikaart)\
**Post date:** [May 15, 2025, 3:45pm UTC](https://discourse.julialang.org/t/multi-dimension-interpolation-with-unitful/129043/1 "2025-05-15T15:45:15Z")

</div>

I am trying to interpolate f : \mathbb{R\_{units}} \to \mathbb{R\_{units}}^3 where there are unitful units on both the grid and the data.

I found this example that showed me how to get f : \mathbb{R} \to \mathbb{R}^3 interpolation working without units, but when I add units it errors out.

This works fine:

```julia
f(a) = 2*a * u"A"
agrid = (0:0.5:5) * u"A"
vals = [f(a) for a in agrid]
itp = interpolate((agrid,), vals, Gridded(Linear()))

```

And so does this:

```julia
f(a) = [1*a, 2*a, 3*a]
agrid = (0:0.5:5) 
vals = [f(a) for a in agrid]
itp = interpolate((agrid,), vals, Gridded(Linear()))

```

But when I combine multi-dim and Units it doesn’t work:

```julia
f(a) = [2*a, 1*a, 3*a] * u"A"
agrid = (0:0.5:5) * u"A"
vals = [f(a) for a in agrid]
itp = interpolate((agrid,), vals, Gridded(Linear()))

```

It throws:

```julia
MethodError: no method matching Interpolations.GriddedInterpolation(::Type{Unitful.Quantity{Float64, 𝐈^2, Unitful.FreeUnits{(A^2,), 𝐈^2, nothing}}}, ::Tuple{StepRangeLen{Unitful.Quantity{Float64, 𝐈, Unitful.FreeUnits{(A,), 𝐈, nothing}}, Base.TwicePrecision{Unitful.Quantity{Float64, 𝐈, Unitful.FreeUnits{(A,), 𝐈, nothing}}}, Base.TwicePrecision{Unitful.Quantity{Float64, 𝐈, Unitful.FreeUnits{(A,), 𝐈, nothing}}}, Int64}}, ::Vector{Vector{Unitful.Quantity{Float64, 𝐈^2, Unitful.FreeUnits{(A^2,), 𝐈^2, nothing}}}}, ::Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}})

The type `Interpolations.GriddedInterpolation` exists, but no method is defined for this combination of argument types when trying to construct it.

```

Is there something I am doing wrong or is Unitful not yet fully supported in Interpolations? (I have run into that with other packages, most work surprisingly well with units but not always)

---

<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:** [May 15, 2025, 3:50pm UTC](https://discourse.julialang.org/t/multi-dimension-interpolation-with-unitful/129043/2 "2025-05-15T15:50:39Z")

</div>

See if [this solution](https://discourse.julialang.org/t/interpolations-with-unitful-vectors/80919/2) helps, basically collecting the ranges to arrays.

---

<div class="post-metadata">

**Author:** ![luke-pikaart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luke-pikaart/32/29361_2.png) [@luke-pikaart](https://discourse.julialang.org/u/luke-pikaart)\
**Post date:** [May 15, 2025, 4:35pm UTC](https://discourse.julialang.org/t/multi-dimension-interpolation-with-unitful/129043/3 "2025-05-15T16:35:48Z")

</div>

Thanks, no I still get the same error when they are vectors.

But maybe I will just use a similar wrapper like they were using to strip and re-attatch units ☹
