1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ I assume you are using Octave, which I believe does not have a Simulink analog. So if you have to code your simulation you could just do it with if else statements. $\endgroup$ – Kwin van der Veen Aug 19 '17 at 2:24
  • $\begingroup$ Scilab is a free option but whatever, Matlab licences are very cheap... $\endgroup$ – Brethlosze Aug 19 '17 at 3:31
  • $\begingroup$ Yes. SciLab has Xcos. But I don't like Xcos for some reason. It feel so poor and cheep. Yes I know that is free, but Octave have a very good symbolic library and a control library. Better that SciLab. $\endgroup$ – Daniel Mårtensson Aug 19 '17 at 8:06
  • $\begingroup$ So I don't need the lsim command ? I can just use a for-loop and a if-ststement? $\endgroup$ – Daniel Mårtensson Aug 19 '17 at 8:11
  • $\begingroup$ @DanielMårtensson Those constraints add nonlinear behavior to the system and those can't be simulation with lsim. You would have to run it with ode45 or equivalent. It might also be possible to formulate it as a jump flow system. I know for a course I had to install an unofficial toolbox for this for MATLAB, so maybe it might also be available for octave. $\endgroup$ – Kwin van der Veen Aug 19 '17 at 8:33
1
$\begingroup$

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) $$

$\endgroup$
  • 1
    $\begingroup$ Can I do something like that in Octave? $\endgroup$ – Daniel Mårtensson Aug 19 '17 at 8:08
  • $\begingroup$ No, there is not a simulink in octave. One could mimic the integration features of simulink by applying an ode45 runge kutta integration, which is part of Octave. But i think that is a very different question. $\endgroup$ – Brethlosze Aug 19 '17 at 12:50
  • 1
    $\begingroup$ Ok. ode45 is not a good ODE solver. It has no input. $\endgroup$ – Daniel Mårtensson Aug 19 '17 at 15:05
  • 1
    $\begingroup$ @DanielMårtensson ode45 only does the integration. The function that you integrate can internally contain the dynamics of your system, including any feedback input. $\endgroup$ – Kwin van der Veen Aug 22 '17 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.