1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2008 - INRIA
5 * Copyright (C) 2015, 2016, 2018 - Samuel GOUGEON
7 * Copyright (C) 2012 - 2016 - Scilab Enterprises
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
17 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
18 xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
19 xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
20 xmlns:scilab="http://www.scilab.org" xml:id="sign" xml:lang="en">
22 <refname>sign</refname>
23 <refpurpose>signum function</refpurpose>
27 <synopsis>X = sign(A)</synopsis>
29 <refsection role="parameters">
30 <title>Arguments</title>
36 matrix of encoded integers, decimal numbers, or complex numbers.
37 <varname>A</varname> may be sparse.
45 matrix of the same size and data type as <varname>A</varname>.
51 <refsection role="description">
52 <title>Description</title>
54 If <varname>X</varname> are integers or real numbers,
57 <literal>X(i) = -1</literal> where <literal>A(i)<0</literal>
60 <literal>X(i) = 0</literal> where <literal>A(i)==0</literal>
63 <literal>X(i) = 1</literal> where <literal>A(i)>0</literal>
66 <literal>X(i)= %nan</literal> where <literal>A(i)</literal> is NaN.
71 If <varname>X</varname> is complex encoded: <literal>sign(A==0) = 0</literal>.
72 Elsewhere, <literal>sign(A) = A./abs(A)</literal>.
75 <refsection role="examples">
76 <title>Examples</title>
77 <para>With decimal numbers:</para>
78 <programlisting role="example"><![CDATA[
79 m = [ 1.25 -2.5 -%inf 2.75
81 %nan 0. -1.5 -2.5 ]; m
96 <para>With complex numbers:</para>
97 <programlisting role="example"><![CDATA[
120 <para>With a sparse matrix:</para>
121 <programlisting role="example"><![CDATA[
122 sign(sprand(8,3,0.3,"normal"))
125 <refsection role="see also">
126 <title>See also</title>
127 <simplelist type="inline">
129 <link linkend="abs">abs</link>
132 <link linkend="csgn">csgn</link>
135 <link linkend="signm">signm</link>
139 <refsection role="history">
140 <title>History</title>
143 <revnumber>6.0</revnumber>
144 <revdescription>Extension to sparse matrices