Can I use discontinuous functions in my model - State space & Transfer function When I simulate physical models I often use state space or transfer function matrecies. I like to use this library: https://octave.sourceforge.io/control/overview.html
Very powerful and well updated. 
But the problem with physical models is that I cannot set some limits for how much input I can have and the displacement and velocity of the model. 
So there are something called discontinuous functions. Simulink has it. Xcos has it and all the other graphical simulation tools. 
For example in Simulink.
http://x-engineer.org/wp-content/uploads/2017/02/Simulink-model-Discontinuities-Library-blocks.jpg
And the results:
http://x-engineer.org/wp-content/uploads/2017/02/Simulink-model-plot-Discontinuities-Library-blocks.png
I'm sorry, I cannot upload pictures here because my webbrowser don't work 100%. It's some small problem with it. Haven't found the solution yet.
So..my question is: Can I create some discontinuous functions with MATLAB/Octave Control packages only? Or do I need to create a for loop or something like that to build my own simulation tool? 
How have you solve this kind of problems?
 A: At least in Matlab, your answer are the S-Functions.
You simply define your dynamic model in a state space function, as any linear, non linear algebraic, or not algebraic function, for each of their stages:


*

*initialize, $x_0$,

*update state, $x=f(t,x)$,

*update output, $y=g(t,x)$,

*finalize.


Besides it is pure code and let Simulink deal with the numerical integration and generic plotting and postprocessing.
If you only need some simplest not dynamical discontinuities, you can use the Matlab Function Blocks or similar for modelling discontinuities. 
Under Octave, or any other pure code languages, one shall remember Simulink is a set of integrators, most based in Runge Kutta methods, such as ode45, ode23, ode15, which essentially integrates the update function $f(t,x)$:
$$
(t,x)=ode45(f,t,x_0,options)
$$
Which solved the main dynamical part of the problem. The output can be easily evaluated if $g$ is properly vectorized:
$$
y=g(t,x)
$$
The mathematical approach of these integrators is to solve the state space evolution $x$ orbiting some equilibrium point, known, ideally set at the origin $x=0$, in where we have all the perturbations, excitations (inputs), measurements (outputs), controlled excitations, etc. as part of a single whole autonomous system:
$$
\frac d {dt}x=f(t,x(t))
$$
Under the control system approach, 
one would like to have a solver taking $u$ as input variable, such that:
$$
\frac{d}{dt}x=f(t,x,u)
$$
Unfortunately, the solvers are focused on the first approach. But this is not a great problem:
For example, a linear time varying dynamical system will be on the form:
$$
\frac{d}{dt}x(t)=f(t,x)=A(t)x+B(t)u(t)+e(t)
$$
Or for the simplest linear dynamical systems:
$$
\frac{d}{dt}x(t)=f(t,x)=Ax+Bu(t)+e(t)
$$
