Error Messages/40626

Example error message



When you evaluate a WhatIf, WhatIfAll, Elasticity, or Dydx, the result variable cannot be indexed by an index that depends on the variable you are varying. Doing so would create an inconsistency, because the index during the WhatIf is different from the index value outside of the WhatIf. The variables are restored to their original values after the WhatIf finishes, so the index's value would no longer be consistent with the index in the result of the WhatIf.

A simple example illustrates the potential inconsistency. Let:

Variable n := 3
Index J := 1..n
Variable y := J^2
Variable Va2 := WhatIf(y, n, 5)

The computed value when n := 5 is a 5-element array, [1, 4, 9, 16, 25], indexed by J. Within the WhatIf, this is fine because J at that time has 5 elements. But after the WhatIf completes, J is restored to 3 elements, so if would be inconsistent to have a 5-element array indexed by a 3-element index.

To avoid such inconsistencies, this error results when you have this situation.


To fix this, you have to restructure something so that the result of your WhatIf uses only indexes that do not depend (directly or indirectly) on the variable that is being temporarily changed by the WhatIf. You might need to re-index it to another index.

The following refinement for Va2 would avoid the problem by introducing a local index for the result:

Variable Va2 := WhatIf( Index J2:=J do y[J=J2], n, 5 )

See Also


You are not allowed to post comments.