MathWorks Machine Translation
The automated translation of this page is provided by a general purpose third party translator tool.
MathWorks does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.
Calculate square root, signed square root, or reciprocal of square root
Simulink / Math Operations
The Sqrt block calculates the square root, signed square root, or reciprocal of square root on the input signal. Select one of the following functions from the Function parameter list.
Function  Description  Mathematical Expression  MATLAB^{®} Equivalent 

sqrt
 Square root of the input 

sqrt

signedSqrt
 Square root of the absolute value of the input, multiplied by the sign of the input 
 — 
rSqrt
 Reciprocal of the square root of the input 
 — 
The block icon changes to match the function.
Port_1
— Input signalInput signal to the block to calculate the square root, signed square
root, or reciprocal of square root. The sqrt
function
accepts real or complex inputs, except for complex fixedpoint signals.
signedSqrt
and rSqrt
do not
accept complex inputs.
If the input is negative, set the Output signal to complex.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
 fixed point
Port_1
— Output signalOutput signal that is the square root, signed square root, or reciprocal of square root of the input signal. When the input is an integer or fixedpoint type, the output must be floating point.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
 fixed point
Function
— Function the block performssqrt
(default)  signedSqrt
 rSqrt
Specify the mathematical function that the block calculates. The block icon changes to match the function you select.
Function  Block Icon 

sqrt
 
signedSqrt
 
rSqrt

Block Parameter:
Operator 
Type: character vector 
Values:
'sqrt'  'signedSqrt'
 'rSqrt' 
Default:
'sqrt' 
Output signal type
— Output signal typeauto
(default)  real
 complex
Specify the output signal type of the block.
Function  Input Signal Type  Output Signal Type  

Auto  Real  Complex  








 








 









Block
Parameter:
OutputSignalType 
Type: character vector 
Values:
'auto'  'real' 
'complex' 
Default:
'auto' 
Sample time
— Specify sample time as a value other than 1
1
(default)  scalarSpecify the sample time as a value other than 1. For more information, see Specify Sample Time.
This parameter is not visible unless it is explicitly set to a value other than
1
. To learn more, see Blocks for Which Sample Time Is Not Recommended.
Block Parameter:
SampleTime 
Type: character vector 
Values: scalar 
Default:
'1' 
Method
— Method to compute reciprocal of square rootExact
(default)  NewtonRaphson
Specify the method for computing the reciprocal of a square root. This
parameter is only valid for the rSqrt
function.
Method  Data Types Supported  When to Use This Method 

Exact
 Floating point If you use a fixedpoint or builtin integer type, an upcast to a floatingpoint type occurs.  You do not want an approximation. NoteThe input or output must be floating point. 
NewtonRaphson
 Floatingpoint, fixedpoint, and builtin integer types  You want a fast, approximate calculation. 
The Exact
method provides results that are
consistent with MATLAB computations.
The algorithms for sqrt
and
signedSqrt
are always of
Exact
type, no matter what selection
appears on the block dialog box.
Block Parameter:
AlgorithmType 
Type: character vector 
Values:
'Exact' 
'NewtonRaphson' 
Default:
'Exact' 
Number of iterations
— Number of iterations used for Newton Raphson algorithm3
(default)  integerSpecify the number of iterations to perform the NewtonRaphson
algorithm. This parameter is valid with the rSqrt
function and the NewtonRaphson
value for
Method.
If you enter 0, the block output is the initial guess of the NewtonRaphson algorithm.
Block Parameter:
Iterations 
Type: character vector 
Values: integer 
Default:
'3' 
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.
Intermediate results data type
— Data type of intermediate resultsInherit:Inherit via internal
rule
(default)  Inherit: Inherit: Inherit from
input
 Inherit: Inherit: Inherit from
output
 double
 single
 int8
 int32
 uint32
 fixdt(1,16,2^0,0)
 <data type expression>
Specify the data type for intermediate results when you set
Function to sqrt
or
rSqrt
on the Main
pane.
The type can be inherited, specified directly, or expressed as a data
type object such as Simulink.NumericType
.
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 nonsingle 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. 
Do not set Intermediate results data type to
Inherit:Inherit from output
when:
You select NewtonRaphson
to
compute the reciprocal of a square root.
The input data type is floating point.
The output data type is fixed point.
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 floatingpoint to fixedpoint data type. For example, insert a Data Type Conversion block in front of the Sqrt block to perform the conversion.
Block Parameter:
IntermediateResultsDataTypeStr 
Type: character vector 
Values: 'Inherit:
Inherit via internal rule'  'Inherit:
Inherit from input'  'Inherit: Inherit
from output'  'double' 
'single' , 'int8' ,
'uint8' , int16 ,
'uint16' , 'int32' ,
'uint32' ,
fixdt(1,16,0) ,
fixdt(1,16,2^0,0) ,
fixdt(1,16,2^0,0) . '<data
type expression>' 
Default: 'Inherit:
Inherit via internal rule' 
Output
— Output data typeInherit: Same as first
input
(default)  Inherit: Inherit via internal rule
 Inherit: Inherit via back
propagation
 double
 single
 int8
 int32
 uint32
 fixdt(1,16,2^0,0)
 <data type expression>
 ...Specify the output data type. The type can be inherited, specified
directly, or expressed as a data type object such as
Simulink.NumericType
.
Block Parameter:
OutDataTypeStr 
Type: character vector 
Values: 'Inherit:
Inherit via internal rule'  'Inherit:
Inherit via back propagation'  'Inherit:
Same as first input'  'double'
 'single' , 'int8' ,
'uint8' , int16 ,
'uint16' , 'int32' ,
'uint32' ,
fixdt(1,16,0) ,
fixdt(1,16,2^0,0) ,
fixdt(1,16,2^0,0) . '<data
type expression>' 
Default: 'Inherit:
Same as first input' 
Lock output data type setting against changes by the fixedpoint tools
— Prevent fixedpoint tools from overriding data typesoff
(default)  on
Select to lock the output data type setting of this block against changes by the FixedPoint Tool and the FixedPoint Advisor. For more information, see Use Lock Output Data Type Setting (FixedPoint Designer).
Block Parameter:
LockScale 
Type: character vector 
Values:
'off' 
'on' 
Default:
'off' 
Saturate on integer overflow
— Choose the behavior when integer overflow occurson
(default)  boolean
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. 
The maximum value that the 
Do not select this check box. 
You want to optimize efficiency of your generated code. You want to avoid overspecifying how a block handles outofrange signals. For more information, see Check for Signal Range Errors. 
Overflows wrap to the appropriate value that is representable by the data type. 
The maximum value that the 
When you select this check box, saturation applies to every internal operation on the block, not just the output or result. Usually, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
Block Parameter:
SaturateOnIntegerOverflow 
Type: character vector 
Value: 'off' 
'on' 
Default: 'on' 
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

For information on HDL code generation support, see Sqrt,Signed Sqrt.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.