# Using Modeling Toolkit to solve simple equation

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.

``````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

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

``````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
``````
1 Like

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

``````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]
``````