Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step function #2

Open
Niimaa opened this issue Jul 26, 2021 · 0 comments
Open

step function #2

Niimaa opened this issue Jul 26, 2021 · 0 comments

Comments

@Niimaa
Copy link

Niimaa commented Jul 26, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant