# Using Modeling Toolkit to solve simple equation

**URL:** <https://discourse.julialang.org/t/using-modeling-toolkit-to-solve-simple-equation/114289>\
**Category:** Modelling & Simulations\
**Tags:** modelingtoolkit\
**Created:** [May 15, 2024, 8:18am UTC](https://discourse.julialang.org/t/using-modeling-toolkit-to-solve-simple-equation/114289 "2024-05-15T08:18:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HSnowden](https://avatars.discourse-cdn.com/v4/letter/h/58f4c7/32.png) [@HSnowden](https://discourse.julialang.org/u/HSnowden)\
**Post date:** [May 15, 2024, 8:18am UTC](https://discourse.julialang.org/t/using-modeling-toolkit-to-solve-simple-equation/114289/1 "2024-05-15T08:18:39Z")

</div>

Hello,  
I shall pretense this with that I am very new to ModelingToolkit  
As part of a bigger system I have a laser source term which chnages based on the type of a struct defining the equation. This means that I want to build a function that defines the laser based on type and make this a modeling toolkit model to the implement elsewhere in my equations. However this equation isn’t a D(t) but rather a f(t) equation. Is there a way to make modeling toolkit solve these without differentiating? Currently when I use structural\_simply(eq) the equation just disappears.

Here is a rough MWE that simulates this and matches my usecase without the multiple dispatch on types.

```julia
function test_eq(;name)
    @parameters a b 
    @variables y(t)

    eqs = [y ~ a*t + b]

    ODESystem(eqs,t;name)
end

@named testeq=test_eq()

testsimp=structural_simplify(testeq)

```

After you run structural\_simplify, the whole equation vanishes as I guess it isn’t a differential equation but I’m not sure.

Thanks for any help

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 15, 2024, 8:49am UTC](https://discourse.julialang.org/t/using-modeling-toolkit-to-solve-simple-equation/114289/2 "2024-05-15T08:49:13Z")

</div>

> [@HSnowden](#):
>
> `y ~ a*t + b`

You don’t need ModelingToolkit for this, Symbolics is enough

```julia
julia> @parameters a b
2-element Vector{Num}:
 a
 b

julia> @variables y
1-element Vector{Num}:
 y

julia> eq = y ~ a*t + b
y ~ b + a*t

julia> Symbolics.solve_for(eq, t)
(-b + y) / a

```

---

<div class="post-metadata">

**Author:** ![HSnowden](https://avatars.discourse-cdn.com/v4/letter/h/58f4c7/32.png) [@HSnowden](https://discourse.julialang.org/u/HSnowden)\
**Post date:** [May 15, 2024, 1:23pm UTC](https://discourse.julialang.org/t/using-modeling-toolkit-to-solve-simple-equation/114289/3 "2024-05-15T13:23:58Z")

</div>

Thank you very much.

Could I then use this to sub into an ODE, as I said prior this is mainly for a time dependent variable. I have shown below how the structure of the code needs to somewhat look like so I assumed that this component would require some form of ODEProblem or equivalent to sub it into further equations

```julia
function (::Gaussian)(;name)
    @parameters FWHM Offset
    @variables tp(t)
    
    eqs = [tp ~ sqrt(4*log(2)/pi)/FWHM*exp(-4*log(2)*(t-(2*FWHM)-Offset)^2/FWHM^2)]
    
    ODESystem(eqs,t;name)
end

function tester(;name)
    @variables S(t) T(t)
    eqs = [D(T) ~ S]

    ODESystem(eqs,t;name)
end

lp=Gaussian(FWHM=100,Offset=300,Power=62,hv=1.55,spatial=[0],R=0.0)
@named gauss_laser=lp()
@named testconnector=tester()

connections = [testconnector.S ~ gauss_laser.tp]

```
