Compatibility Check failing depending on variable definition

3 views (last 30 days)
Good Morning,
I was running the compatibility check on a model and I got the following error:
The model contains initializations to non-finite numbers.
I have then tried to dig into the model, cause I was not getting any more information on what was causing the problem (related to this: there is a way to increase verbosity level of the compatibility check?). Finally, I found the "culprit" that was triggering this error: in a few words, there were indeed some variables that were initialized to "Inf", but that at the end weren't used. To solve this problem, I tried using if-clause to prevent the calculation of such variables in case of division by zero (which was causing the Inf initialization), but also for this case the compatibility check was failing.
Attached I reproduced the part of the model which is giving me incompatibility. Basically there are two variables:
x1 = var1;
x2 = var1 + offset;
Where var1 and offset are parameters, that are set to var1 = 1 and offset = 0. The two variables are then fed into a if-clause as follow:
if abs(x1 - x2) < eps
y = 1;
else
y = 1 / (x1 - x2);
end
In the older version, I didn't had the if-clause. For this case, I would expect the compatibility check to not fail, as I'm not initializing any variable to Inf.
Aside from this, I could report another strange behaviour. If the x1 and x2 variable are defined as:
x1 = var1;
x2 = offset;
and the parameters to var1 = 1 and offset = 1, then for this case the compatibility check do not fail as before!
In my opinion, the compatibility check should not fail in these cases, because those are exactly cases where a Design Error check to detect division-by-zero would be really useful! Unfortunately for such a case with parameters, the design error check does not detect these potential division-by-zero, even though the constants are defined though usage of parameters, which can take different values depending on the needings of the customer.
Best,
Davide

Answers (0)

Categories

Find more on Model Compatibility in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!