simulink preventing signal below 0

57 views (last 30 days)
Tom
Tom on 17 Jan 2014
Commented: Andreas Goser on 17 Jan 2014
Hi,
I have a model which runs fast but the problem is that simulink takes to big time steps and by this the signal goes below zero. My model has exponential functions and thus will never go below zero. But because a too big time step close to 0 the signal jumps below zero and I get errors of derivative inputs being infinite. Is there a way to prevent simulink from getting values below 0 because due to the model this could normally not happen. I still want simulink to calculate fast (thus changing the absolute/relative error margins is not advisable because this seems to work but the simulation time for the values which are far from 0 takes 50 times longer) but only if he sees that it becomes zero that he goes back to the past and take smaller time steps. It is also not zero crossing because he will search for a value which he will never be able to find. Can somebody help me with this problem?
Tom Wambecq

Answers (2)

Andreas Goser
Andreas Goser on 17 Jan 2014
Edited: Andreas Goser on 17 Jan 2014
OK, you seem to be aware of the numerical risks of addressing this issue not by solver settings...
In this case I suggest the block "Saturation" and set the lower limit to 0 and the upper limit to a reasonable value you will not reach anyway or inf.
  2 Comments
Tom
Tom on 17 Jan 2014
Hi,
this would change the value and not force simulink to step back in time when he sees a negative value and take at that point smaller values. Are there other options?
Tom Wambecq
Andreas Goser
Andreas Goser on 17 Jan 2014
I would say "You can't eat the cake and have it".

Sign in to comment.


Haiko
Haiko on 17 Jan 2014
A simple possibility is to add a few blocks to your system.
For example a switch block. Using the normal input when larger than zero and z zero input when smaller than zero.
Anonther easy solution would be an if block and subsystems.
Something like this:
if (u1 > 0) {
body_1;
}
elseif (u1 < 0){
body_2; % with in the subblock a gain of zero
}
else {
body_3;
}
Anonther easy solution would be a switch block. Using the normal input when larger than zero and z zero input when smaller than zero.
  1 Comment
Tom
Tom on 17 Jan 2014
Hi,
this is also adjusting the signal after it has been calculated while I want simulink to step back and take smaller steps to avoid the negative values. It is all good solutions but unfortunately not applicable in my situation. Thanks already for the examples and solutions. If you have more options to somehow force the solver to do different things: feel free to tell me.
Tom Wambecq

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!