MATLAB: Block eror

s-functionsimulink

Good afternoon. Prompt please, I have s-function in language C. This block gives out the following error:
Derivative input 1 of 'sfundebug/S-Function' at time 0.0 is Inf or NaN. Stopping simulation. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances).
What callback method is responsible for this parameter?

Best Answer

The error message tells you "The derivative of [...] is infinite".
The place in your s-function where you specify the derivative of states is where you use "ssGetdX".
I recommend using downloading visual studio, mexing your s-function in debug mode (-g flag) and stepping through your code line by line. You should be able to easily identify what part of your mdlDerivative sets the state derivative to INF or NAN.