I have a model which takes the root of the input in an matlab function block. The input should always positive; however, sometimes simulink gives a negative number. The reason is that i use an implicit solver (ode15s due to other part of the system being stiff) and simulink have a invalid estimate. My question is: how can I tell simulink that the input is invalid which makes the solver take a smaller step (without stopping)? Can I return a special value (e.g., NaN) or throw an error (without stopping the simulation)?
3 Answers
0
votes
0
votes
Use the Hit Crossing Block to force the solver to take small time steps as your signal approaches zero. This will work assuming your model is correctly set up to force the signal to go no lower than zero (i.e. it works something like an Abs block, which will hit zero and then continue with a positive value).
0
votes
My solution was to add another output, isInputValid. This is 0 if the input is invalid and 1 if the input is valid. This output is then integrated by a new integration block. It seems like the discontinuity produced by the boolean variable makes sure that the integrator takes smaller steps.
Example:
if ( u<0)
y = -realmax;
isInputValid = 0;
else
y = sqrt(u);
isInputValid = 1;
end
Then attach an integrator to the output of isInputValid.