blob: f7ce939681200486960712456fe3b26bea19c1b6 (
plain)
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin math::complexnumbers n 1.0.2]
[keywords {complex numbers}]
[keywords math]
[copyright {2004 Arjen Markus <arjenmarkus@users.sourceforge.net>}]
[moddesc {Tcl Math Library}]
[titledesc {Straightforward complex number package}]
[category Mathematics]
[require Tcl 8.3]
[require math::complexnumbers [opt 1.0.2]]
[description]
[para]
The mathematical module [emph complexnumbers] provides a straightforward
implementation of complex numbers in pure Tcl. The philosophy is that
the user knows he or she is dealing with complex numbers in an abstract
way and wants as high a performance as can be had within the limitations
of an interpreted language.
[para]
Therefore the procedures defined in this package assume that the
arguments are valid (representations of) "complex numbers", that is,
lists of two numbers defining the real and imaginary part of a
complex number (though this is a mere detail: rely on the
[emph complex] command to construct a valid number.)
[para]
Most procedures implement the basic arithmetic operations or elementary
functions whereas several others convert to and from different
representations:
[para]
[example {
set z [complex 0 1]
puts "z = [tostring $z]"
puts "z**2 = [* $z $z]
}]
would result in:
[example {
z = i
z**2 = -1
}]
[section "AVAILABLE PROCEDURES"]
The package implements all or most basic operations and elementary
functions.
[para]
[emph {The arithmetic operations are:}]
[list_begin definitions]
[call [cmd ::math::complexnumbers::+] [arg z1] [arg z2]]
Add the two arguments and return the resulting complex number
[list_begin arguments]
[arg_def complex z1 in]
First argument in the summation
[arg_def complex z2 in]
Second argument in the summation
[list_end]
[para]
[call [cmd ::math::complexnumbers::-] [arg z1] [arg z2]]
Subtract the second argument from the first and return the
resulting complex number. If there is only one argument, the
opposite of z1 is returned (i.e. -z1)
[list_begin arguments]
[arg_def complex z1 in]
First argument in the subtraction
[arg_def complex z2 in]
Second argument in the subtraction (optional)
[list_end]
[para]
[call [cmd ::math::complexnumbers::*] [arg z1] [arg z2]]
Multiply the two arguments and return the resulting complex number
[list_begin arguments]
[arg_def complex z1 in]
First argument in the multiplication
[arg_def complex z2 in]
Second argument in the multiplication
[list_end]
[para]
[call [cmd ::math::complexnumbers::/] [arg z1] [arg z2]]
Divide the first argument by the second and return the resulting complex
number
[list_begin arguments]
[arg_def complex z1 in]
First argument (numerator) in the division
[arg_def complex z2 in]
Second argument (denominator) in the division
[list_end]
[para]
[call [cmd ::math::complexnumbers::conj] [arg z1]]
Return the conjugate of the given complex number
[list_begin arguments]
[arg_def complex z1 in]
Complex number in question
[list_end]
[para]
[list_end]
[para]
[emph {Conversion/inquiry procedures:}]
[list_begin definitions]
[call [cmd ::math::complexnumbers::real] [arg z1]]
Return the real part of the given complex number
[list_begin arguments]
[arg_def complex z1 in]
Complex number in question
[list_end]
[para]
[call [cmd ::math::complexnumbers::imag] [arg z1]]
Return the imaginary part of the given complex number
[list_begin arguments]
[arg_def complex z1 in]
Complex number in question
[list_end]
[para]
[call [cmd ::math::complexnumbers::mod] [arg z1]]
Return the modulus of the given complex number
[list_begin arguments]
[arg_def complex z1 in]
Complex number in question
[list_end]
[para]
[call [cmd ::math::complexnumbers::arg] [arg z1]]
Return the argument ("angle" in radians) of the given complex number
[list_begin arguments]
[arg_def complex z1 in]
Complex number in question
[list_end]
[para]
[call [cmd ::math::complexnumbers::complex] [arg real] [arg imag]]
Construct the complex number "real + imag*i" and return it
[list_begin arguments]
[arg_def float real in]
The real part of the new complex number
[arg_def float imag in]
The imaginary part of the new complex number
[list_end]
[para]
[call [cmd ::math::complexnumbers::tostring] [arg z1]]
Convert the complex number to the form "real + imag*i" and return the
string
[list_begin arguments]
[arg_def float complex in]
The complex number to be converted
[list_end]
[para]
[list_end]
[para]
[emph {Elementary functions:}]
[list_begin definitions]
[call [cmd ::math::complexnumbers::exp] [arg z1]]
Calculate the exponential for the given complex argument and return the
result
[list_begin arguments]
[arg_def complex z1 in]
The complex argument for the function
[list_end]
[para]
[call [cmd ::math::complexnumbers::sin] [arg z1]]
Calculate the sine function for the given complex argument and return
the result
[list_begin arguments]
[arg_def complex z1 in]
The complex argument for the function
[list_end]
[para]
[call [cmd ::math::complexnumbers::cos] [arg z1]]
Calculate the cosine function for the given complex argument and return
the result
[list_begin arguments]
[arg_def complex z1 in]
The complex argument for the function
[list_end]
[para]
[call [cmd ::math::complexnumbers::tan] [arg z1]]
Calculate the tangent function for the given complex argument and
return the result
[list_begin arguments]
[arg_def complex z1 in]
The complex argument for the function
[list_end]
[para]
[call [cmd ::math::complexnumbers::log] [arg z1]]
Calculate the (principle value of the) logarithm for the given complex
argument and return the result
[list_begin arguments]
[arg_def complex z1 in]
The complex argument for the function
[list_end]
[para]
[call [cmd ::math::complexnumbers::sqrt] [arg z1]]
Calculate the (principle value of the) square root for the given complex
argument and return the result
[list_begin arguments]
[arg_def complex z1 in]
The complex argument for the function
[list_end]
[para]
[call [cmd ::math::complexnumbers::pow] [arg z1] [arg z2]]
Calculate "z1 to the power of z2" and return the result
[list_begin arguments]
[arg_def complex z1 in]
The complex number to be raised to a power
[arg_def complex z2 in]
The complex power to be used
[list_end]
[list_end]
[vset CATEGORY {math :: complexnumbers}]
[include ../doctools2base/include/feedback.inc]
[manpage_end]
|