MATLAB: Does XY Graph affect algebraic loop solver

algebraic loopMATLABsimulink

I have a model involving an algebraic loop that mysteriously refuses to solve ONLY when an XY Graph is attached. I don't think the model's exact purpose is important, but you can read more about it here. I'm using Matlab & Simulink 2011a. The observations I think are important are:
  • This model works fine as-is
  • When you change Constant1 from 4.8 to 5, the model will no longer solve — you'll get the error message "Algebraic state in algebraic loop containing 'algebraicscope/Sum1' computed at time 0.0 is Inf or NaN"
  • When you then delete the XY Graph block from the model (and leave Constant1 as 5), the model will again solve just fine (the normal scope can be used to verify results; there should be a constant line of value 0 and a constant line of value 4)
It is the simple presence of the XY Graph that prevents Simulink from solving the model under certain conditions! As a beginner in Simulink, it is extremely disturbing to me that the presence of a read-only debugging tool can affect the solution of a model. Am I thinking about something wrong, or is this actually a bug?
This is a graphic of the model in question:

Best Answer

The problem is that adding blocks to your model (such as the XY Graph) causes the sorted order of all the blocks to change. Since there are no clear data dependencies in an algebraic system like this (which Simulink normally can use to provide a consistent sorted order), adding blocks can cause seemingly random changes. There is nothing special about the XY Block in particular, you will get the same issue if you add a display block to both the X and Y signals for example.
I believe the problem with changing the sorted order is that depending on which blocks are executing first, Simulink will automatically select an initial guess for that block's output. If that guess happens to be poor, the solution will diverge and you get no answer. If that guess is reasonable then it will converge on a solution.
When you want to force Simulink to solve an algebraic equation, a good approach is to use the Algebraic Constraint block. This allows you to explicitly specify an initial guess for one of the parameters and have a more consistent result. For example, here is a revision of your model using the Algebraic Constraint block with X as the algebraic state: