BondGraphTools / BondGraphTools-Tutorials

A set of Jupyter Workbooks and tutorials for the BondGraphTools pagakge.
Apache License 2.0
0 stars 2 forks source link

step function #2

Open Niimaa opened 3 years ago

Niimaa commented 3 years ago

Hi there, seems like the step function code in the tutorial has some mistakes as it gives me the following error:

ModelException: Invalid control function for var: 0. Control functions should be of the form: 0 = f(t, x, dx/dt)

from BondGraphTools import *

#%%

model = new(name= 'RC')

#%%
C = new("C", value= 1)
R = new("R", value= 1)
KCL = new("0")

#%%

add(model, R, C, KCL)
connect(R, KCL)
connect(KCL, C)

#%%

Sf = new("Sf")
add(model, Sf)
connect(Sf, KCL)
draw(model)

#%%
timespan = [0, 5]
x0 = {'x_0':1}

step_fn = {'u_0': 't < 1 ? 1 : 0'} # if t < 0 then 1 else 0
t, x = simulate(model, timespan=timespan, x0=x0, control_vars= step_fn)
plot(t,x)

Thanks