| Contents | Index |
Math Operations
You can select one of the following functions from the Function parameter list.
| Function | Description | Mathematical Expression | MATLAB Equivalent |
|---|---|---|---|
| sqrt | Square root of the input | u0.5 | sqrt |
| signedSqrt | Square root of the absolute value of the input, multiplied by the sign of the input | sign(u)*|u|0.5 | — |
| rSqrt | Reciprocal of the square root of the input | u-0.5 | — |
The block output is the result of applying the function to the input. Each function supports:
Scalar operations
Element-wise vector and matrix operations
The block accepts input signals of the following data types:
| Function | Input Data Types | Restrictions |
|---|---|---|
sqrt |
| None |
signedSqrt |
| When the input is an integer or fixed-point type, the output must be floating point. |
rSqrt |
| None |
The block accepts real and complex inputs of the following types:
| Function | Types of Real Inputs | Types of Complex Inputs |
|---|---|---|
sqrt | Any, except for fixed-point inputs that are negative or have nontrivial slope and nonzero bias | Any, except for fixed-point inputs |
signedSqrt | None | |
rSqrt | None |
The block output:
Uses the data type that you specify for Output data type
Is real or complex, depending on your selection for Output signal type
The Main pane of the block dialog box appears as follows:

Specify the mathematical function. The block icon changes to match the function you select.
| Function | Block Icon |
|---|---|
| sqrt |
|
| signedSqrt |
|
| rSqrt |
|
Specify the output signal type of the block as auto, real, or complex.
| Function | Input Signal Type | Output Signal Type | ||
|---|---|---|---|---|
| Auto | Real | Complex | ||
sqrt | real | real for nonnegative inputs nan for negative inputs | real for nonnegative inputs nan for negative inputs | complex |
complex | complex | error | complex | |
signedSqrt | real | real | real | complex |
complex | error | error | error | |
rSqrt | real | real | real | error |
complex | error | error | error | |
Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See How to Specify the Sample Time in the online documentation for more information.
The Algorithm pane of the block dialog box appears as follows:

Note The parameters in the Algorithm pane are available only when you set Function to rSqrt on the Main pane. |
Specify the method for computing the reciprocal of a square root.
| Method | Data Types Supported | When to Use This Method |
|---|---|---|
| Exact | Floating point If you use a fixed-point or built-in integer type, an upcast to a floating-point type occurs. | You do not want an approximation. |
| Newton-Raphson | Floating-point, fixed-point, and built-in integer types | You want a fast, approximate calculation. |
The Exact method provides results that are consistent with MATLAB computations.
Specify the number of iterations to perform the Newton-Raphson algorithm. The default value is 3.
This parameter is not available when you select Exact for Method.
The Data Types pane of the block dialog box appears as follows:

Specify the data type for intermediate results (available only when you set Function to sqrt or rSqrt on the Main pane). You can set the data type to:
A rule that inherits a data type, for example, Inherit:Inherit via internal rule
The name of a built-in data type, for example, single
The name of a data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Follow these guidelines on setting an intermediate data type explicitly for the square root function, sqrt:
| Input and Output Data Types | Intermediate Data Type |
|---|---|
| Input or output is double. | Use double. |
| Input or output is single, and any non-single data type is not double. | Use single or double. |
| Input and output are fixed point. | Use fixed point. |
Follow these guidelines on setting an intermediate data type explicitly for the reciprocal square root function, rSqrt:
| Input and Output Data Types | Intermediate Data Type |
|---|---|
| Input is double and output is not single. | Use double. |
| Input is not single and output is double. | Use double. |
| Input and output are fixed point. | Use fixed point. |
Caution Do not set Intermediate results data type to Inherit:Inherit from output when:
Under these conditions, selecting Inherit:Inherit from output yields suboptimal performance and produces an error. To avoid this error, convert the input signal from a floating-point to fixed-point data type. For example, insert a Data Type Conversion block in front of the Sqrt block to perform the conversion. |
Specify the output data type. You can set the data type to:
A rule that inherits a data type, for example, Inherit:Inherit via back propagation
The name of a built-in data type, for example, single
The name of a data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Output
data type parameter.
See Specifying Block Output Data Types for more information.
Specify the minimum value that the block can output. The default value is [] (unspecified). Simulink uses this value to perform:
Simulation range checking (see Signal Ranges)
Automatic scaling of fixed-point data types
Specify the maximum value that the block can output. The default value is [] (unspecified). Simulink uses this value to perform:
Simulation range checking (see Signal Ranges)
Automatic scaling of fixed-point data types
Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.
Specify the rounding mode for fixed-point operations. For more information, see Rounding in the Simulink Fixed Point User's Guide.
| Action | Reasons for Taking This Action | What Happens for Overflows | Example |
|---|---|---|---|
Select this check box. | Your model has possible overflow and you want explicit saturation protection in the generated code. | Overflows saturate to either the minimum or maximum value that the data type can represent. | An overflow associated with a signed 8-bit integer can saturate to -128 or 127. |
Do not select this check box. | You want to optimize efficiency of your generated code. You want to avoid overspecifying how a block handles out-of-range signals. For more information, see Checking for Signal Range Errors. | Overflows wrap to the appropriate value that is representable by the data type. | The number 130 does not fit in a signed 8-bit integer and wraps to -126. |
When you select this check box, saturation applies to every internal operation on the block, not just the output or result. In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
Suppose that you have the following model:

When the input to the Sqrt block is negative and the Output signal type is auto or real, the sqrt function outputs nan. However, setting Output signal type to complex produces the correct answer.
Suppose that you have the following model:

When the input to the Sqrt block is negative, the block output is the same for any Output signal type setting. If you change the first Display block format from short to decimal (Stored Integer), you see the value of the imaginary part for the complex output.

Suppose that you have the following model:

In the Sqrt block dialog box, assume that the following parameter settings apply:
| Parameter | Setting |
|---|---|
| Method | Newton-Raphson |
| Number of iterations | 1 |
| Intermediate results data type | Inherit:Inherit from input |
After one iteration of the Newton-Raphson algorithm, the block output is within 0.0004 of the final value (0.4834).
Suppose that you have the following model:

In the Sqrt block dialog box, assume that the following parameter settings apply:
| Parameter | Setting |
|---|---|
| Method | Newton-Raphson |
| Number of iterations | 1 |
| Intermediate results data type | Inherit:Inherit from input |
After one iteration of the Newton-Raphson algorithm, the block output is within 0.0459 of the final value (0.4834).
Direct Feedthrough | Yes |
Sample Time | Specified in the Sample time parameter |
Dimensionalized | Yes |
Multidimensionalized | Yes |
Zero-Crossing Detection | No |
Math Function, Trigonometric Function

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |