MATLAB Answers

1

How are math operations of constants in simulink models performed?

Asked by Michael Knörzer on 2 May 2019
Latest activity Commented on by Michael Knörzer on 3 May 2019
Are the results calculated at every simulation step or are they calculated only once at the beginning of the simulation?
example:
If I have two constants a and b. In Simulink I call them through constant blocks and add them using an add block. Does the solver calculate this sum at each calculation step or does it calculate the sum only once?

  0 Comments

Sign in to comment.

2 Answers

Answer by Thomas
on 2 May 2019
 Accepted Answer

Hi Michael,
It depends how you have configured the sample time for your Simulink constant blocks and maths blocks. If they have a sample time of inf then they will only be calculated once. If not they will be calcuated at the sample time assigned.
Regards
Tom

  1 Comment

Hi Tom,
thanks for the fast response. The answer has helped me a lot!
Regards Michael

Sign in to comment.


Answer by Raj
on 2 May 2019

The computation is done at each simulation step time. So if you are adding two constant blocks, from t=start of simulation to t=end of simulation, Simulink computes the sum at each sampling time step.

  4 Comments

Show 1 older comment
I am not quite convinced. I still think Simulink computes output throughout the simulation. Consider this case for example:
Capture.JPG
Basically I am adding two constants but I am changing the value of second constant in the middle of simulation using a switch condition. If the sum was computed only in the beginning as you say then the summer output should have been a constant value. But that is not the case. The output is changing as you can see below:
Capture.JPG
Can you explain where I am going wrong here?
In this case you are correct, the answer is not constant and is computed throughout, but this isn't the case asked by Michael. In your example you don't have 2 constants being added. The sample time of the signal coming from the switch will be driven by your signal builder block creating a varying signal. If you had Michaels example described above you could configure it to computer once or multiple times.
If you compute this example setting the sample time of the add block to t_s > 5s the scope will show constant two.

Sign in to comment.