Variation between data during simulation and that stored for use in second simulation

1 view (last 30 days)
Hello,
I am working on a simulation for a system that uses a feedbackloop to correct for any system deviations. At each time step of the simulation the outout and input values are stored. I have another system wich is the exact same as the previous system just without the feedback loop. The data collected from the first system (with feedback loop) is then used to control the second system with almost no issue. After a while, however, an error starts to creap in and is notiacable at about 6 decimal places.
I have connected both systems so that the output from the system with the feedback loop is directly fed into the system without the feedback loop and there are no erroes biult up in this arrangment. If I then use that exact data again (stored from the first run with the feedback loop used) on the system without the feedback loop again an error builds up over time.
I am therefore wondering if anyone has any suggestions why this may be and how I can possibaly mitigate this issue.
Thanks
Kas

Answers (2)

Fangjun Jiang
Fangjun Jiang on 11 Jan 2023
Edited: Fangjun Jiang on 12 Jan 2023
I think I understand your question. I will use this diagram from https://en.wikipedia.org/wiki/Control_theory to explain.
You have this diagram simulated in Simulink and recorded the data at "System input" and "System output".
Now you duplicate the block "System" to "System2" in the same model, feed the recorded data "System input" and record the output as "System Output2". You expect "System Output" and "System Output2" to match exactly but they don't.
The most likely cause is that the "System input" recorded is not exactly the same as the "System input" in the closed-loop. There will be truncated error (rounding error) when recording the data.
If you feed the closed-loop "System input" to both "System" and "System2", you might get "System output" and "System ouput2" to match. But they could still be different, due to the different execution order of the components inside "System" and "System2".
But the most important point I want to bring up here is this. If you have a fine-tuned closed-loop control system, don't expect to get the same ouput if you apply the recorded control input to the same system in open loop fashion. In theory, it should. But in real world, there will always be disturbance. In Simulation, data accuracy loss is sufficient to cause the difference, especially when "System" is un-stable.
This is the fundermentals of closed-loop control. With closed-loop, there is self-regulation, self-correction. Open-loop doesn't have it.
  8 Comments
Fangjun Jiang
Fangjun Jiang on 13 Jan 2023
The "configuration of blocks" is not the same between System and System2, when System is in the loop with Controller and Sensor, while System2 is only connected to the output of Controller.
Imaging all the blocks are flatterned, due to the loop, the algorithm determines that it is best to start the execution order at the middle of System, going through Sensor, then Reference, then Controller, and then the left half of System. System2 is also in the model, but it is easy to infer the execution order would be from "System input" to the right end of System2. In this case, in the same time step, the relative execution order inside System and System2 is different.
The discussion I had with the Mathworker is about code generation, becaused we had cases where the generated codes are different for System and System2. The code differences are not about variable names, but rather, the different order of some lines of code. When the discussion is moved to the execution order of Simulink blocks, I basically asked this exact question. If I have two identical subsystems in the model, would the execution order of internal blocks be the same. The answer is no. Or "It depends", Or "Well, likely not if the system is complex."
Paul
Paul on 13 Jan 2023
Commenting only on simulation, not code generation, I'm having a hard time conceptually coming up with how that scenario (in the second paragraph) can happen. At the end of the day, System represents the mathematical relationship between its output and System Input. System2 represents the exact same mathematical relationship to the exact same input. So it's highly disturbing to me that Simulink would simulate the exact same mathematical relationships differently. If TMW says that can be the case, then I guess that can be the case. Doesn't make it any less troubling. But thanks for bringing it up. Definitely something to be aware of.

Sign in to comment.


Fangjun Jiang
Fangjun Jiang on 13 Jan 2023
@Paul, I am determined to persuade you on this. Luckily, I was able to make an example quickly. See attached model in R2022b.
  • Subsystem1 is copy and paste from Subsystem, Turn on Information Overlays, Execution Order.
  • Inside Subsystem, the relative execution order, from top to bottom, is 2, 1, 4, 3
  • Inside Subsystem1, the relative execution order, from top to bottom, is 1, 2, 4, 3
  6 Comments
Paul
Paul on 14 Jan 2023
I think you meant to compare c and C.
I'll give this more thought. But I don't find your code example convincing. From what I've seen so far, the effect of different block execution order would actually look like this:
% Subsystem 1, assume 2e40 is the input
a=1e30+2e40; % block a
b=eps; % block b
c=a+b; % block c
% Subsystem 2, assume 2e40 is the input, the blocks have to have the same definitions, just a
% different sequence
B=eps; % block b, same output, evaluated before block a
A=1e30 + 2e40; % block a
C=A+B; % block c
c == C
ans = logical
1
Anyway, at this point I don't think we'll get any further absent a specific Simulink model that demonstrates the behavior, which I suspect would have to be quite complex as you say. So I guess I'll just leave it here and, as I said, continue to give the matter more thought.
Fangjun Jiang
Fangjun Jiang on 14 Jan 2023
Yes. I meant "c==C". But Yes, it is an invalid example. The operations were different.
I must have been thinking about code generation again. I remember we had cases where different codes were generated for the same subsystem, to the effect of, for System, it was "output=a+b+c". For System1, it was "interim=a+b;output=interim+c".

Sign in to comment.

Categories

Find more on Schedule Model Components in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!