1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2011 - DIGITEO - Michael Baudin
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 * Copyright (C) 2020 - Samuel GOUGEON
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
18 xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
19 xmlns:scilab="http://www.scilab.org" xml:id="complex" xml:lang="en">
21 <refname>complex</refname>
22 <refpurpose>Build an array of complex numbers from their parts</refpurpose>
32 <title>Arguments</title>
37 scalars, vectors, matrices or hypermatrices of real numbers.
38 If both <varname>a</varname> and <varname>b</varname> are not
39 scalars, they must have the same sizes.
46 array of complex numbers, of the size of <varname>u</varname> or of
47 <varname>a</varname> and <varname>b</varname>.
48 If <varname>u</varname> is sparse, or if <varname>a</varname> and
49 <varname>b</varname> have the same sizes and both are sparse,
50 then <varname>c</varname> is also sparse.
51 Otherwise <varname>c</varname> is dense-encoded.
58 <title>Description</title>
60 <emphasis role="bold">c = complex(u)</emphasis> creates an array
61 of complex numbers from their real parts <varname>u</varname>,
62 and zero as imaginary parts.
65 <emphasis role="bold">c = complex(a,b)</emphasis> creates an array
66 of complex numbers from their respective real parts <varname>a</varname>
67 and their imaginary parts <varname>b</varname>.
70 This function is equivalent to <literal>a + imult(b)</literal>, which
71 handles properly special Inf and NaN real and imaginary parts.
75 <title>Examples</title>
77 In the following example, we create a complex number from
78 its real and imaginary parts.
80 <programlisting role="example"><![CDATA[
85 If <varname>a</varname> only is specified, then the imaginary
88 <programlisting role="example"><![CDATA[
92 If <varname>a</varname> is a scalar and <varname>b</varname>
93 is a matrix, then the result <varname>c</varname> has the same
94 size as <varname>b</varname>.
95 Similarly, if <varname>b</varname> is a scalar and <varname>a</varname>
96 is a matrix, then the result <varname>c</varname> has the same
97 size as <varname>a</varname>.
99 <programlisting role="example"><![CDATA[
100 c = complex([1 2 3], 4)
101 c = complex(1, [2 3 4])
104 If <varname>a</varname> and <varname>b</varname> are two
105 matrices with different sizes, an error is generated, as in the
109 -->complex(ones(2,3),ones(4,5))
111 complex: Incompatible input arguments #1 and #2: Same sizes expected.
112 at line 33 of function complex called by :
113 complex(ones(2,3),ones(4,5))
116 With special real or/and imaginary parts:
118 <programlisting role="example"><![CDATA[
119 r = [0 0 0 %inf %inf %inf %nan %nan %nan].';
120 i = [0 %inf %nan 0 %inf %nan 0 %inf %nan].';
123 // Then let's compare complex(r, i) with r + i*%i :
124 [complex(r,i), r+i*%i]
139 // Then let's compare complex(r, i) with r + i*%i :
140 --> [complex(r,i), r+i*%i]
146 Inf + Infi Nan + Infi
147 Inf + Nani Nan + Nani
149 Nan + Infi Nan + Infi
150 Nan + Nani Nan + Nani
153 <refsection role="see also">
154 <title>See also</title>
155 <simplelist type="inline">
157 <link linkend="percenti">%i</link>
160 <link linkend="imult">imult</link>
164 <refsection role="history">
165 <title>History</title>
168 <revnumber>6.1.1</revnumber>
169 <revdescription>Extension to sparse arrays.