-
Notifications
You must be signed in to change notification settings - Fork 57
/
complex_numbers.html
181 lines (150 loc) · 5.06 KB
/
complex_numbers.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<html>
<head>
<title>
COMPLEX_NUMBERS - Complex Numbers in MATLAB Programming
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
COMPLEX_NUMBERS <br> Complex Numbers in MATLAB Programming
</h1>
<hr>
<p>
<b>COMPLEX_NUMBERS</b> is a MATLAB program which
demonstrates very briefly some of the features of using complex
numbers in a MATLAB program.
</p>
<p>
The first issue is how to declare a complex variable, including
the choice of single precision or double precision, whether
the variable is a scalar, vector, or array, and whether the variable
is initialized with a value, or assigned one.
</p>
<p>
A second issue concerns the question of how a complex variable is
to be printed out.
</p>
<p>
Another issue concerns how a complex variable is to operated on
by the arithmetic operators of addition, subtraction, multiplication,
division, and exponentiation.
</p>
<p>
The language also provides a number of intrinsic functions that
can be applied to a complex variable. The names of these functions
can sometimes be easy to forget. Moreover, it is occasionally true
that there may be a selection of functions with similar names
(say, "exp", "cexp" and "dcexp") which may or may not produce the
desired results.
</p>
<p>
Another issue concerns the details of double precision calculation.
Even a single accidental use of a single precision function name
in a double precision computation can result in the loss of half
the digits of accuracy. Thus, it sometimes really matters whether
you use "cmplx" or "dcmplx" to assign values to a double precision
complex variable.
</p>
<p>
One peculiar feature of MATLAB is that the symbols <b>i</b> and <b>j</b>
are predefined as functions that return the value of the complex unit.
Unless the user redefines them (for example, by using a <b>for</b>
statement in which <b>i</b> is an index) then they can be used to
set up complex quantities:
<pre>
a = 1 + 2 * i;
b = 1 + 2 * j;
</pre>
</p>
<p>
Another peculiar feature of MATLAB is that the <b>printf</b> command
will only print the real part of a complex number. To get the real
and imaginary parts, you must explicitly request them:
<pre>
a = 1 + 2 * i;
fprintf ( 1, ' %f %f\n', a ); <-- not correct!
fprintf ( 1, ' %f %f\n', real ( a ), imag ( a ) ); <--correct!
</pre>
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>COMPLEX_NUMBERS</b> is available in
<a href = "../../c_src/complex_numbers/complex_numbers.html">a C version</a> and
<a href = "../../cpp_src/complex_numbers/complex_numbers.html">a C++ version</a> and
<a href = "../../f77_src/complex_numbers/complex_numbers.html">a FORTRAN77 version</a> and
<a href = "../../f_src/complex_numbers/complex_numbers.html">a FORTRAN90 version</a> and
<a href = "../../m_src/complex_numbers/complex_numbers.html">a MATLAB version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../m_src/blas1_c/blas1_c.html">
BLAS1_C</a>,
a MATLAB library which
contains basic linear algebra routines for vector-vector operations,
using single precision complex arithmetic;
</p>
<p>
<a href = "../../m_src/blas1_z/blas1_z.html">
BLAS1_Z</a>,
a MATLAB library which
contains basic linear algebra routines for vector-vector operations,
using double precision complex arithmetic.
</p>
<p>
<a href = "../../m_src/c8lib/c8lib.html">
C8LIB</a>,
a MATLAB library which
implements certain elementary functions for "C8"
or double precision complex variables;
</p>
<p>
<a href = "../../m_src/linpack_c/linpack_c.html">
LINPACK_C</a>,
a MATLAB library which
solves linear systems using single precision complex arithmetic;
</p>
<h3 align = "center">
Source Code:
</h3>
<p>
<ul>
<li>
<a href = "complex_numbers.m">complex_numbers.m</a>,
the source code.
</li>
</ul>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<ul>
<li>
<a href = "complex_numbers_output.txt">complex_numbers_output.txt</a>,
the output file;
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../m_src.html">
the MATLAB source codes</a>.
</p>
<hr>
<i>
Last revised on 07 November 2010.
</i>
<!-- John Burkardt -->
</body>
</html>