MATLAB: Does the final result of a Simulink model change when other independent parts of the model are modified

simulink

I have developed a Simulink model that is used to simulate a very long physical process. I am noticing that the final result of the simulation is slightly different depending on how many blocks there are in the model. The blocks that are added should not affect the value of concern because they are added to a different branch of the model not upstream of this calculation.
The differences in results are indeed negligible, but the final result computed is the output of an integrator block. And since the model simulates a physical process over hundreds of days, the minute numerical errors accumulate over time. The simulation is run in normal mode, and uses a variable step solver which is automatically chosen to be "ode45" by the solver's heuristics.
A simplified model demonstrating this effect is attached. In this model, the absolute value of an input signal is computed in a branch parallel to the main computation. If this "abs" block is commented-out, the final result of the main branch is noticeably different. Adding more blocks to alternate branches of the simulation also causes the value to change.
What is happening in the simulation to cause such different results?

Best Answer

The behavior described is due to how the variable step solver is interacting with the constraints and calculations of the Simulink model.
These model constraints include the Relative tolerance and Absolute tolerance parameters specified in the model's configuration parameters. In order to calculate solutions within these tolerances, the solver needs to work harder by taking additional minor time steps. For a brief explanation on minor time steps, please refer to the following link:
The model consists of mostly continuous sample time. A benefit of a continuous sample time is the ability to use a variable-step continuous solver such as "ode45". Minor time steps are unique to continuous solvers, and enable Simulink to take more steps to refine a solution. A powerful application of this is in Zero-Crossing Detection that helps the solver resolve discontinuities that appear during simulation. Please refer to the following link on Zero-Crossing Detection:
On this page there is a list of blocks that detect and register zero-crossings, and "abs" is one of these blocks.
Any blocks that register zero-crossing detection can cause the solver to take additional minor time steps. Even if a single "abs" block is added to a model, this would change the number of time steps taken, and may result in a slightly different solution. These solutions do however conform to the tolerances specified in the configuration parameters of the model.
Although a certain calculation may be computed identically in two models, achieving a perfect match in results between the two may not be possible. However, you may be able to get the results closer by reducing the tolerance specifications in Configuration Parameters > Solver. Tightening the allowed tolerances should make the deviations in results smaller, though this will increase the amount of time it takes your simulation to finish.
The Simulink Debugger can be a valuable tool for inspecting which signals in a model are being driven by the solver tolerance settings. Refer to the following two links regarding using the Simulink Debugger for this purpose: