Assigning value to time dependent symbolic function inside a function


In the following code:

using ModelingToolkit

@variables t 

@register_symbolic u(t)

u(t) = 60

is there a way I can assign a value to u(t) from inside a function? The following doesn’t work.

function assignValue(x)
	u(t) = x


What are you trying to accomplish? Given the information you have provided, you might as well do

@variables u(t)

equations = [
    u ~ 60

Hi, thanks for the response.

I want to simulate a modelingtoolkit model from python. Something like this:

# Importing the model
from julia import Main

# Control input
u = 60

# Simulate
sol = Main.solveModel(u)

So, I want to be able to change the control input value from python.

If the input is always a constant, you can encode it as a parameter using @parameters and then change the value by providing a new value in the parameter map when creating the ODEProblem.

That worked! Thanks a lot :blush:

1 Like