block eror

3 次查看(过去 30 天)
Natalia
Natalia 2011-3-5
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?
  1 个评论
Natalia
Natalia 2011-3-5
Code part
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 0);
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S))
{ }
ssSetNumContStates(S, 18);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 4)) return;
ssSetInputPortWidth(S, 0, 1);
ssSetInputPortWidth(S, 1, 1);
ssSetInputPortWidth(S, 2, 1);
ssSetInputPortWidth(S, 3, 1);
ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 18)) return;
ssSetOutputPortWidth(S, 0, 1);
ssSetOutputPortWidth(S, 1, 1);
ssSetOutputPortWidth(S, 2, 1);
ssSetOutputPortWidth(S, 3, 1);
ssSetOutputPortWidth(S, 4, 1);
ssSetOutputPortWidth(S, 5, 1);
ssSetOutputPortWidth(S, 6, 1);
ssSetOutputPortWidth(S, 7, 1);
ssSetOutputPortWidth(S, 8, 1);
ssSetOutputPortWidth(S, 9, 1);
ssSetOutputPortWidth(S, 10, 1);
ssSetOutputPortWidth(S, 11, 1);
ssSetOutputPortWidth(S, 12, 1);
ssSetOutputPortWidth(S, 13, 1);
ssSetOutputPortWidth(S, 14, 1);
ssSetOutputPortWidth(S, 15, 1);
ssSetOutputPortWidth(S, 16, 1);
ssSetOutputPortWidth(S, 17, 1);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
}
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
ssSetModelReferenceSampleTimeDefaultInheritance(S);
}
#define MDL_INITIALIZE_CONDITIONS
static void mdlInitializeConditions(SimStruct *S)
{
real_T *x0 = ssGetContStates(S);
int_T lp;
for (lp=0;lp<2;lp++) {
*x0++=0.0;
}
}
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T *y = ssGetOutputPortRealSignal(S,0);
real_T *x = ssGetContStates(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
UNUSED_ARG(tid);
y[0]=x[0];
y[1]=x[1];
y[2]=x[2];
y[3]=x[3];
y[4]=x[4];
y[5]=x[5];
y[6]=x[6];
y[7]=x[7];
y[8]=x[8];
y[9]=x[9];
y[10]=x[10];
y[11]=x[11];
y[12]=x[12];
y[13]=x[13];
y[14]=x[14];
y[15]=x[15];
y[16]=x[16];
y[17]=x[17];
}
#define MDL_DERIVATIVES
static void mdlDerivatives(SimStruct *S)
{
real_T *dx = ssGetdX(S);
real_T *x = ssGetContStates(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
time_T dt = ssGetFixedStepSize(S);
....
}

请先登录,再进行评论。

采纳的回答

Guy Rouleau
Guy Rouleau 2011-3-6
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.

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by