Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Math Function - Perform mathematical function

Library

Math Operations

Description

The Math Function block performs numerous common mathematical functions.

You can select one of the following functions from the Function parameter list.

FunctionDescriptionMathematical ExpressionMATLAB Equivalent
exp

Exponential

eu

exp
log

Natural logarithm

ln u

log
10^u

Power of base 10

10u

10.^u
(see power)

log10

Common (base 10) logarithm

log u

log10
magnitude^2

Complex modulus

|u|2

(abs(u)).^2
(see abs and power)

square

Power 2

u2

u.^2
(see power)

sqrt

Square root

u0.5

sqrt
1/sqrt

Reciprocal of a square root

u-0.5

pow

Power

uv

power
conj

Complex conjugate

ū

conj
reciprocal

Reciprocal

1/u

1./u
(see rdivide)

hypot

Square root of sum squares

(u2+v2)0.5

hypot
rem

Remainder after division

rem
mod

Modulus after division

mod
transpose

Transpose

uT

u.'
(see arithmetic operators)

hermitian

Complex conjugate transpose

uH

u'
(see arithmetic operators)

The block output is the result of the operation of the function on the input or inputs. The functions support the following types of operations.

FunctionScalar OperationsElement-Wise Vector and Matrix OperationsVector and Matrix Operations
exp

yes

yes

log

yes

yes

10^u

yes

yes

log10

yes

yes

magnitude^2

yes

yes

square

yes

yes

sqrt

yes

yes

1/sqrt

yes

yes

pow

yes

yes

conj

yes

yes

reciprocal

yes

yes

hypot

yes, on two inputs

yes, on two inputs (two vectors or two matrices of the same size, a scalar and a vector, or a scalar and a matrix)

rem

yes, on two inputs

yes, on two inputs (two vectors or two matrices of the same size, a scalar and a vector, or a scalar and a matrix)

mod

yes, on two inputs

yes, on two inputs (two vectors or two matrices of the same size, a scalar and a vector, or a scalar and a matrix)

transpose

yes

yes

hermitian

yes

yes

The name of the function appears on the block. The appropriate number of input ports appears automatically.

Data Type Support

The following table shows the input data types that each function of the block can support.

Functionsingledoublebooleanbuilt-in integerfixed point

exp

yes

yes

log

yes

yes

10^u

yes

yes

log10

yes

yes

magnitude^2

yes

yes

yes

yes

square

yes

yes

yes

yes

sqrt

yes

yes

yes

yes

1/sqrt

yes

yes

yes

yes

pow

yes

yes

conj

yes

yes

yes

yes

reciprocal

yes

yes

yes

yes

hypot

yes

yes

rem

yes

yes

yes

mod

yes

yes

yes

transpose

yes

yes

yes

yes

yes

hermitian

yes

yes

yes

yes

All supported modes accept both real and complex inputs, except for reciprocal, sqrt, and 1/sqrt, which do not accept complex fixed-point inputs. Also, sqrt and 1/sqrt do not accept fixed-point inputs that are negative or have nontrivial slope and nonzero bias.

The block output is real or complex, depending on what you select for Output signal type. For 1/sqrt, the output is always real and you cannot change the setting for Output signal type.

Parameters and Dialog Box

The Main pane of the Math Function block dialog box appears as follows:

Function

Specify the mathematical function. See Description for more information about the options for this parameter.

Output signal type

Specify the output signal type of the Math Function block as real, complex, or auto.

 InputOutput Signal Type
FunctionSignalAutoRealComplex

exp, log, 10u, log10, square, sqrt, pow, reciprocal, conjugate, transpose, hermitian

real

complex

real

complex

real

error

complex

complex

magnitude squared

real

complex

real

real

real

real

complex

complex

hypot, rem, mod

real

complex

real

error

real

error

complex

error

1/sqrt

real

complex

real

error

Not available

Not available

Sample time (-1 for inherited)

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 Signal Attributes pane of the Math Function block dialog box appears as follows:

Output minimum

Specify the minimum value that the block can output. The default value, [], is equivalent to -Inf. Simulink software uses this value to perform:

Output maximum

Specify the maximum value that the block can output. The default value, [], is equivalent to Inf. Simulink software uses this value to perform:

Output data type

Specify the output data type. You can set it 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.

Lock output data type setting against changes by the fixed-point tools

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.

Integer rounding mode

Select the rounding mode for fixed-point operations. For more information, see Rounding in the Simulink Fixed Point User's Guide.

Saturate on integer overflow

If selected, fixed-point overflows saturate. Otherwise, overflows wrap.

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 which case, no saturation code is necessary.

The Intermediate Attributes pane of the Math Function block dialog box appears as follows:

Intermediate results data type

Specify the data type for intermediate results. You can set it to:

  • Inherit: Inherit via internal rule (default)

  • Inherit: Inherit from input

  • Inherit: Inherit from output

    Tip   Do not select Inherit: Inherit from output under these conditions:

    • You select Newton-Raphson 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 an error results.

    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 Math Function block to perform the conversion.

Method

Select the method for computing the reciprocal of a square root.

MethodData Types SupportedWhen to Use This Method
Newton-Raphson (default)

Floating-point, fixed-point, and built-in integer types

You want a fast, approximate calculation.

Exact

Floating-point

If you use a fixed-point or built-in integer type, an upcast to a floating-point type occurs.

You want an exact calculation.

    Note   The input or output must be floating-point.

Number of iterations

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 the Method.

Characteristics

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes, of the input when the function requires two inputs

Dimensionalized

Yes

Multidimensionalized

Yes, for all functions except hermitian and transpose

Zero-Crossing Detection

No

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS