Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

step function #2

@Niimaa

Description

@Niimaa

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions