# Performance of Interpolations in Modeling toolkit

**URL:** <https://discourse.julialang.org/t/performance-of-interpolations-in-modeling-toolkit/97997>\
**Category:** Modelling & Simulations\
**Tags:** performance, interpolations, modelingtoolkit, differentialequation, simulations\
**Created:** [April 27, 2023, 1:53pm UTC](https://discourse.julialang.org/t/performance-of-interpolations-in-modeling-toolkit/97997 "2023-04-27T13:53:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HamzaKh99](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamzakh99/32/49279_2.png) [@HamzaKh99](https://discourse.julialang.org/u/HamzaKh99)\
**Post date:** [April 27, 2023, 1:53pm UTC](https://discourse.julialang.org/t/performance-of-interpolations-in-modeling-toolkit/97997/1 "2023-04-27T13:53:10Z")

</div>

Hello,

I’m trying to create a lookup table function in modeling toolkit, for that I used Interpolations.jl to make an interpolation between elements of a table, my code is working perfectly fine but the problem is in the performance and the number of allocations, I used the profiler to find the source of the problem, and it’s in the interpolation,

> function interpolateMatrix(X1,X2,Data::Matrix{Float64},bp1::Vector{Float64},bp2::Vector{Float64})  
> interpolator = linear\_interpolation((bp1::Vector{Float64}, bp2::Vector{Float64}), Data::Matrix{Float64},extrapolation\_bc=Flat())  
> return interpolator(X1,X2)  
> end  
> @register interpolateMatrix(X1::Float64,X2::Num,Data::Matrix{Float64},bp1::Vector{Float64},bp2::Vector{Float64})::Float64  
> function LookupTable1D(;name)  
> @parameters lintype::Float64  
> @variables u(t)=0 y(t)=0  
> eqs = [scalarize(y ~ interpolateMatrix(lintype,u,Tabledata::Matrix{Float64},bp1::Vector{Float64},bp2::Vector{Float64}));  
> ]  
> ODESystem(eqs;name)  
> end

when I test the interpolation function alone it’s fast  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/0/d015940fe6e8094d2c0ff536d51341b04a9403ac.png)  
When I use it in a modeling toolkit system it’s very slow,

 ![Capture d’écran 2023-04-27 154009](https://global.discourse-cdn.com/julialang/original/3X/9/7/97beba084aa8a347c19beee187b93edbb4e75bb9.png)  
If you can give me advice or solutions for this problem I’ll be thankful.  
here is the data I’m using ;

> Tabledata1 =[[0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10];  
> [0 0.635 1.27 1.9 2.54 3.175 3.81 4.445 5.08 5.715 6.35 6.975 7.514 8.03 8.54 8.995 9.35 9.599 9.762 9.896 10];  
> [0 0.6 1.2 1.8 2.4 3 3.6 4.2 4.8 5.4 6 6.6 7.155 7.639 8.109 8.532 8.916 9.292 9.621 9.827 9.98];  
> [0 0.8 1.6 2.4 3.2 4 4.8 5.6 6.393 6.985 7.508 8.012 8.376 8.661 8.929 9.19 9.433 9.632 9.79 9.93 10];  
> [0 0.7 1.4 2.1 2.8 3.5 4.2 4.9 5.557 6.147 6.728 7.306 7.869 8.29 8.661 9.02 9.369 9.637 9.807 9.944 10]]  
> bp111 =[0.0,1.0,2.0,3.0,4.0]  
> bp21 =[0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10]  
> lintype = 3.0

---

<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:** [April 27, 2023, 2:51pm UTC](https://discourse.julialang.org/t/performance-of-interpolations-in-modeling-toolkit/97997/2 "2023-04-27T14:51:51Z")

</div>

It needs work. It’s just not good right now and we know it 😅. We also know why though, and so it’s on the roadmap for solving in the near future.
