Main Content

ssSetStateAbsTol

Set the absolute tolerance used by a variable-step solver for a specific S-function continuous state.

Syntax

void ssSetStateAbsTol(SimStruct *S, const int_T idx, const Real_T val)

Arguments

S

SimStruct that represents an S-Function block.

idx

An index that represents an S-function continuous state. This index ranges from 0 to n-1 where n is the number of continuous states in the S-function.

val

The value of the absolute tolerance. The value must be a positive real scalar.

Description

Use to set the absolute tolerances used for S-function continuous states by the variable-step solver for the current simulation.

Note

Absolute tolerances are not allocated for fixed-step solvers. Therefore, you should never invoke this macro until you have verified that the simulation is using a variable-step solver. You can use ssIsVariableStepSolver to determine whether or not the model is using a variable-step solver.

Languages

C, C++

Examples

/*
 * Set the absolute tolerances based on the parameters
 */
static void mdlStart(SimStruct *S)
{
    const real_T absTol0 = ( mxGetPr(ssGetSFcnParam(S,0)) )[0];
    const real_T absTol1 = ( mxGetPr(ssGetSFcnParam(S,1)) )[0];
    
    /* Absolute tolerance is not used by fixed-step solvers
     * Therefore every call to absolute tolerance API must be guarded
     */

    if ( ssIsVariableStepSolver(S) ) {
        ssSetStateAbsTol(S, 0, absTol0);    
        ssSetStateAbsTol(S, 1, absTol1);    
    }
}

See the S-function sfun_atol.c used in sfcndemo_sfun_atol for a complete example that uses this function.

Version History

Introduced in R2011a