13
13
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="complex" xml:lang="en">
15
<refname>complex</refname>
16
<refpurpose>Create a complex number.</refpurpose>
19
<title>Calling Sequence</title>
26
<title>Arguments</title>
32
a 1-by-1 or a n-by-m real matrix of doubles, the real part.
33
If <literal>a</literal> has an imaginary part, an error
42
a 1-by-1 or a n-by-m real matrix of doubles, the imaginary part (default b=0).
43
If <literal>b</literal> has an imaginary part, an error
51
<para>a n-by-m complex matrix of doubles, the complex number.</para>
57
<title>Description</title>
59
c=complex(a) creates a complex number from its real part <literal>a</literal>
60
and zero as the imaginary part.
63
c=complex(a,b) creates a complex number from its real part <literal>a</literal>
64
and imaginary part <literal>b</literal>.
67
This function is a substitute for expressions such as <literal>a+%i*b</literal>,
68
especially in cases where the complex arithmetic interferes with particular
69
floating point numbers such as <literal>%inf</literal> or
70
<literal>%nan</literal>.
74
<title>Examples</title>
76
In the following example, we create a complex number from
77
its real and imaginary parts.
79
<programlisting role="example"><![CDATA[
15
<refname>complex</refname>
16
<refpurpose>Create a complex number.</refpurpose>
19
<title>Calling Sequence</title>
26
<title>Arguments</title>
32
a 1-by-1 or a n-by-m real matrix of doubles, the real part.
33
If <literal>a</literal> has an imaginary part, an error
42
a 1-by-1 or a n-by-m real matrix of doubles, the imaginary part (default b=0).
43
If <literal>b</literal> has an imaginary part, an error
51
<para>a n-by-m complex matrix of doubles, the complex number.</para>
57
<title>Description</title>
59
c=complex(a) creates a complex number from its real part <literal>a</literal>
60
and zero as the imaginary part.
63
c=complex(a,b) creates a complex number from its real part <literal>a</literal>
64
and imaginary part <literal>b</literal>.
67
This function is a substitute for expressions such as <literal>a+%i*b</literal>,
68
especially in cases where the complex arithmetic interferes with particular
69
floating point numbers such as <literal>%inf</literal> or
70
<literal>%nan</literal>.
74
<title>Examples</title>
76
In the following example, we create a complex number from
77
its real and imaginary parts.
79
<programlisting role="example"><![CDATA[
81
81
complex([1 2],[3 4])
82
82
]]></programlisting>
84
If <literal>a</literal> only is specified, then the imaginary
87
<programlisting role="example"><![CDATA[
84
If <literal>a</literal> only is specified, then the imaginary
87
<programlisting role="example"><![CDATA[
89
89
]]></programlisting>
91
If <literal>a</literal> is a scalar and <literal>b</literal>
92
is a matrix, then the result <literal>c</literal> has the same
93
size as <literal>b</literal>.
94
Similarily, if <literal>b</literal> is a scalar and <literal>a</literal>
95
is a matrix, then the result <literal>c</literal> has the same
96
size as <literal>a</literal>.
98
<programlisting role="example"><![CDATA[
91
If <literal>a</literal> is a scalar and <literal>b</literal>
92
is a matrix, then the result <literal>c</literal> has the same
93
size as <literal>b</literal>.
94
Similarily, if <literal>b</literal> is a scalar and <literal>a</literal>
95
is a matrix, then the result <literal>c</literal> has the same
96
size as <literal>a</literal>.
98
<programlisting role="example"><![CDATA[
99
99
c = complex([1 2 3], 4)
100
100
c = complex(1, [2 3 4])
101
101
]]></programlisting>
103
If <literal>a</literal> and <literal>b</literal> are two
104
matrices with different sizes, an error is generated, as in the
103
If <literal>a</literal> and <literal>b</literal> are two
104
matrices with different sizes, an error is generated, as in the
108
108
-->complex(ones(2,3),ones(4,5))
110
110
complex: Incompatible input arguments #1 and #2: Same sizes expected.
111
111
at line 33 of function complex called by :
112
112
complex(ones(2,3),ones(4,5))
115
The purpose of the <literal>complex</literal> function is to manage
116
IEEE floating point numbers such as Nans or Infinities.
117
In the following example, we show that creating a complex number where
118
the real and imaginary parts are complex is not straightforward if
119
we use the complex arithmetic.
120
This is because the product <literal>%i</literal> times <literal>%inf</literal>
121
is evaluated as <literal>(0+%i) * (%inf+%i*0)</literal>.
122
This produces the intermediate expression <literal>0*%inf</literal>,
123
which is <literal>%nan</literal>.
115
The purpose of the <literal>complex</literal> function is to manage
116
IEEE floating point numbers such as Nans or Infinities.
117
In the following example, we show that creating a complex number where
118
the real and imaginary parts are complex is not straightforward if
119
we use the complex arithmetic.
120
This is because the product <literal>%i</literal> times <literal>%inf</literal>
121
is evaluated as <literal>(0+%i) * (%inf+%i*0)</literal>.
122
This produces the intermediate expression <literal>0*%inf</literal>,
123
which is <literal>%nan</literal>.
131
The solution of this issue is to use the <literal>complex</literal>
131
The solution of this issue is to use the <literal>complex</literal>
135
135
-->complex(%inf,%inf)
140
<refsection role="see also">
141
<title>See Also</title>
142
<simplelist type="inline">
144
<link linkend="imult">imult</link>
140
<refsection role="see also">
141
<title>See Also</title>
142
<simplelist type="inline">
144
<link linkend="imult">imult</link>