# New interpolation method ModelingToolkit

**URL:** <https://discourse.julialang.org/t/new-interpolation-method-modelingtoolkit/123000>\
**Category:** General Usage\
**Tags:** modelingtoolkit\
**Created:** [November 23, 2024, 7:25pm UTC](https://discourse.julialang.org/t/new-interpolation-method-modelingtoolkit/123000 "2024-11-23T19:25:25Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![cryptic.ax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cryptic.ax/32/220540_2.png) [@cryptic.ax](https://discourse.julialang.org/u/cryptic.ax)\
**Post date:** [November 24, 2024, 7:01am UTC](https://discourse.julialang.org/t/new-interpolation-method-modelingtoolkit/123000/3 "2024-11-24T07:01:15Z")

</div>

Regarding your root comment using the explicit interpolation parameter:

> [@langestefan](#):
>
> Trying to initialize this results in:
> 
> > ERROR: LoadError: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol

Could you give an example for how you’re creating the model? The code snippet only includes the model definition. In addition, I would recommend specifying a more concrete type than `Function` for type stability. If you want to swap out the function after building the model, you could go the `FunctionWrapper` route and declare it as `I_L(::Float64)::Float64`.

* * *

As for the second approach using `ParametrizedInterpolation`:

> I got rid of the explicit parameter method and replaced it by `ParametrizedInterpolation`:

There are two problems with this model:

`ParametrizedInterpolation` is created outside the `@mtkmodel` and used inside. This doesn’t include it as a subcomponent. It seems that the way `ParametrizedInterpolation` is defined prevents it from being used inside `@components`, which is something the standard library should probably fix. In the meantime, the last few lines of `function SingleDiode` should be:

```julia
@named sys = Single_Diode()
sys = compose(sys, [I_L])
structural_simplify(sys)

```

The second problem is the reason your system is unbalanced. The `ParametrizedInterpolation` needs an input, using which it samples the data. It does not sample with respect to time by default. If you wish to sample with respect to time, you can add `I_L.input.u ~ t` to the equations.

An additional performance enhancement for this approach:

Judging from the root comment, it seems you do not need the interpolation data as a parameter. In such a case, you can replace `ParametrizedInterpolation` with `Interpolation`, which simply stores the interpolant as a callable symbolic.

---

_[View the full topic](https://discourse.julialang.org/t/new-interpolation-method-modelingtoolkit/123000)._
