# Interpolation in Modeling Toolkit

**URL:** <https://discourse.julialang.org/t/interpolation-in-modeling-toolkit/128094>\
**Category:** New to Julia\
**Tags:** modelingtoolkit\
**Created:** [April 15, 2025, 12:48pm UTC](https://discourse.julialang.org/t/interpolation-in-modeling-toolkit/128094 "2025-04-15T12:48:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaviJR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/javijr/32/218294_2.png) [@JaviJR](https://discourse.julialang.org/u/JaviJR)\
**Post date:** [April 15, 2025, 12:48pm UTC](https://discourse.julialang.org/t/interpolation-in-modeling-toolkit/128094/1 "2025-04-15T12:48:41Z")

</div>

Hello everyone,  
I’m gradually getting into the Julia ecosystem and I find it fascinating. I’m experimenting with developing models using ModelingToolkit.jl and I’ve come across a challenge that I haven’t been able to solve. I would like to create a system that, based on the simulation time, outputs data according to values stored in a CSV file.

The documentation shows how to do this using an interpolation block via functions, but I’m wondering if the same can be achieved using the `@mtkmodel` ecosystem.

I’m attaching a diagram of the model I want to implement (which currently isn’t working) to see if anyone could help me figure it out.

```julia
#datos.value and datos.time are columns of a dataframe.
begin

	@mtkmodel CSVSource begin
		@parameters begin
		data=datos.value
		time=datos.time
		end
		@components begin
			clock = ContinuousClock(offset = 0, start_time = 0)
			inter = Interpolation(LinearInterpolation, u= data , x = time)
			transfer = TransferFunction(b=[1 2], a=[1 3 2])
		end
		@equations begin
			connect(clock.output,inter.input)
			connect(inter.output,transfer.input)
		end
	end

	
end

```

Best regards.

---

<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 15, 2025, 4:07pm UTC](https://discourse.julialang.org/t/interpolation-in-modeling-toolkit/128094/2 "2025-04-15T16:07:00Z")

</div>

@SebastianM-C

---

<div class="post-metadata">

**Author:** ![SebastianM-C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebastianm-c/32/2480_2.png) [@SebastianM-C](https://discourse.julialang.org/u/SebastianM-C)\
**Post date:** [April 17, 2025, 9:55am UTC](https://discourse.julialang.org/t/interpolation-in-modeling-toolkit/128094/3 "2025-04-17T09:55:00Z")

</div>

The issue here is that the model macro does not currently support positional arguments. I’ll try to define a fallback that’s compatible with the macro, but that makes it harder (or impossible) to pass both an arbitrary number of positional and keyword arguments to the underlying interpolation.

---

<div class="post-metadata">

**Author:** ![SebastianM-C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebastianm-c/32/2480_2.png) [@SebastianM-C](https://discourse.julialang.org/u/SebastianM-C)\
**Post date:** [May 30, 2025, 12:15pm UTC](https://discourse.julialang.org/t/interpolation-in-modeling-toolkit/128094/4 "2025-05-30T12:15:14Z")

</div>

As of [Release v2.21.1 · SciML/ModelingToolkitStandardLibrary.jl · GitHub](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/releases/tag/v2.21.1) you should be able to use the interpolation block with the `@mtkmodel` macro.

Note that since in `Interpolation` the `data` and `time` are not symbolic parameters, you have to construct the interpolation object either outside of the model macro or wrapped in a `begin`/`end` block, so that it’s not considered as being symbolic.

See the example in the docs for more details: [SampledData Component · ModelingToolkitStandardLibrary.jl](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/tutorials/input_component/#Interpolation-Block)

Let me know if you have any issues with this.
