1

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?

euraad
  • 3,052
  • 4
  • 35
  • 79
  • 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. – Kwin van der Veen Aug 19 '17 at 02:24
  • Scilab is a free option but whatever, Matlab licences are very cheap... – Brethlosze Aug 19 '17 at 03:31
  • 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. – euraad Aug 19 '17 at 08:06
  • So I don't need the lsim command ? I can just use a for-loop and a if-ststement? – euraad Aug 19 '17 at 08:11
  • @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. – Kwin van der Veen Aug 19 '17 at 08:33
  • Maybe I should try SciLab again... I think there is a lack of symbolic use in Scilab. – euraad Aug 19 '17 at 11:25
  • @DanielMårtensson Here is the toolbox I was talking about. So if you can model it as a jump flow system (which should be possible if it is piece wise linear), then you might be able to use this, since a lot of MATLAB code also runs on Octave. – Kwin van der Veen Aug 19 '17 at 12:39
  • @KwinvanderVeen I think the hybrid system approach is very useful for combining very different dynamical behaviors which justify using different integrators per system. But if we are talking about individual blocks that would not be the case. If i am introducing some hysteresys or limits, even some ifthen conditions. – Brethlosze Aug 19 '17 at 13:08
  • @DanielMårtensson i think you should consider keeping on octave, which is on my though more potent than scilab. If you are working for a university, matlab is really cheap, and almost a standard with tons of resources. I dont think scilab is still so well developed. That is another question though. The key part is you still have to choose an integrator in simulink, which you also can do direclty by calling it. – Brethlosze Aug 19 '17 at 13:12
  • @KwinvanderVeen So I don't need Simulink for this library? Ony Octave? – euraad Aug 19 '17 at 14:58
  • @hyprfrcb I not working at a university, but I work with automation. I'm also a teacher and a engineer. I agree that SciLab is poor made and Octave is more powerful. One bad thing with Octave's contol package is that it's over 2 years old and not updated since 2015 and the developer seems to have quit. One good thing with SciLab is Xcos and a their control package is updated often. https://help.scilab.org/docs/6.0.0/en_US/section_64a8529216e858b335b0e6c058385350.html – euraad Aug 19 '17 at 15:04
  • I think I will use SciLab for some days and create som LQG, H-inf controllers. Just to feel how SciLab is today. – euraad Aug 19 '17 at 15:22
  • Matlab is the choice if you are not student. 100 bucks a license is not a great deal. – Brethlosze Aug 20 '17 at 07:44
  • But then I only get MATLAB, no toolbox such as control toolbox, symbolic toolbox and robust toolbox. – euraad Aug 20 '17 at 09:38
  • @hyprfrcb Yep! I quit with SciLab and its controll package. Back to Octave with the Octave's control package again. Much more stable, even if the library is very old. – euraad Aug 20 '17 at 17:33

1 Answers1

1

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

Brethlosze
  • 3,097
  • 1
    Can I do something like that in Octave? – euraad Aug 19 '17 at 08:08
  • 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. – Brethlosze Aug 19 '17 at 12:50
  • 1
    Ok. ode45 is not a good ODE solver. It has no input. – euraad Aug 19 '17 at 15:05
  • 1
    @DanielMårtensson ode45 only does the integration. The function that you integrate can internally contain the dynamics of your system, including any feedback input. – Kwin van der Veen Aug 22 '17 at 03:33