Python: discrete changes to dynamic equations depending on state

Hi,

I was wondering if there is a way to add discrete changes to the dynamic equations of the system similar to this example from the ACADO toolkit: http://acado.sourceforge.net/doc/html/d0/d7e/example_005.html.

The model I am currently working on is a NMPC controller for a mass spring damper. I wish to make the spring stiffness (k) vary with displacement (x). For example:
0 < x < 0.5 → k = 50
x < 0 → k = 100
x > 0.5 → k = 200

Any help is greatly appreciated.

Thanks, Jonte