# Matrix interpolations

**URL:** https://discourse.julialang.org/t/matrix-interpolations/31888
**Category:** New to Julia
**Created:** [December 5, 2019, 4:28am UTC](https://discourse.julialang.org/t/matrix-interpolations/31888 "2019-12-05T04:28:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Egwene\_al\_Vere](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@Egwene\_al\_Vere](https://discourse.julialang.org/u/Egwene_al_Vere)
#### Post date: [December 5, 2019, 4:28am UTC](https://discourse.julialang.org/t/matrix-interpolations/31888/1 "2019-12-05T04:28:31Z")

</div>

I’m trying out `Interpolations.jl` for matrix-valued data, for this example `Linear` runs but `Cubic` fails.

```julia
using LinearAlgebra
using Interpolations

f(t) = [cos(t) -sin(t); sin(t)*im cos(t)]
ts = 0:.01:2*pi
fs = [f(ti) for ti in ts]

itp = interpolate(fs, BSpline(Cubic(Line(OnGrid())))) # fails

itp = interpolate(fs, BSpline(Linear())) #works
ifx = scale(itp, ts)

```

The error message is `MethodError: no method matching zero(::Type{Array{Complex{Float64},2}})` The documentation of `Interpolations.jl` seems a bit sparse. How can one solve this problem? Thanks a lot!

---

<div class="post-metadata">

### Author: ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)
#### Post date: [December 5, 2019, 5:36am UTC](https://discourse.julialang.org/t/matrix-interpolations/31888/2 "2019-12-05T05:36:28Z")

</div>

That error tells you that at some point, Interpolations tried to call `zero` on the _type_ of one of your matrices returned by `f(t)`, which is not defined (and it can’t be, since the size of the matrix is not encoded in the type). Its really just an artifact of how Interpolations.jl is written though, since it might otherwise try to call `zero` on the matrix itself, which would have worked.

In any case, barring changing Interpolations.jl, you can have your function return a StaticMatrix, which _does_ have the size encoded in the type. If you do the following, the rest of your code works:

```julia
using StaticArrays
f(t) = @SMatrix[cos(t) -sin(t); sin(t)*im cos(t)]

```

You might also get some speedups since StaticArrays are faster for operations on small matrices, exactly like the ones you have there.

Note though that it looks like evaluating the interpolation is slower than just evaluating `f(t)`, so depending on what your actual problem is you may not want to do the interpolation at all.
