1

How can I determine value from previous time step during simulation in Modelica? I have equation Q=m*c*(Ts2-Ts1-Tr) I need to extract value of Ts2 and Ts1 from it.

  • Ts2 - is the value from time step 2
  • Ts1 - is value from previous time step
  • Ts is input signal and it has variations during the time. Each step it has different value. In my case time step is 1s. Other values are fixed.

Can I set in equation variable time? For example:

Ts2 (start=time);
Ts (start=time-1);

Or it should be input inside this model?

regards Tymofii

stardust
  • 5,918
  • 1
  • 18
  • 20
Tymo
  • 259
  • 6
  • 14
  • possible duplicate: http://stackoverflow.com/questions/15517892/how-to-use-the-value-of-the-variable-in-the-previous-interval-as-an-input-to-the – matth May 15 '13 at 13:35

1 Answers1

4

This was addressed in a similar question already.

The key point is that equations describing physical behavior cannot refer to time steps. This is because there is no "timestep" in nature or the laws of physics and so the response of a system cannot depend on it.

You don't really explain why you need to do what you are doing. Are you trying to extract simulation results? Are you trying to correlate to experimental data? Or, are you just trying to solve a differential equation?

It isn't clear what you want to do. Please elaborate and we can probably give you some guidance on how to proceed in Modelica.

Update

Using values from a "previous interval" is fine. For example, if you wanted to sample your solution at regular intervals, express a "z transform" or implement a Kalman Filter in Modelica, you could do each of those very easily (for example, see the 'sample' keyword here). In other words, it is possible to store as many previous values as you would like.

What you cannot do is use the timestep of the continuous solver in expressing how your system behaves. The intervals you reference must be independent from any intervals that the solver is using.

Community
  • 1
  • 1
Michael Tiller
  • 9,291
  • 3
  • 26
  • 41
  • Thank you, this is exactly my situation. I would like to put value of variable from previous interval into equation. Is it mean that it's not correct to build model in such way? – Tymo May 16 '13 at 06:15
  • I updated my answer above to clarify things. But you need to explain what this previous value is being used for. Why do you need a previous value? Does your system have some kind of "memory" or other state that affects its behavior? – Michael Tiller May 20 '13 at 19:44