1math::complexnumbers(n) Tcl Math Library math::complexnumbers(n)
2
3
4
5______________________________________________________________________________
6
8 math::complexnumbers - Straightforward complex number package
9
11 package require Tcl 8.3
12
13 package require math::complexnumbers ?1.0.2?
14
15 ::math::complexnumbers::+ z1 z2
16
17 ::math::complexnumbers::- z1 z2
18
19 ::math::complexnumbers::* z1 z2
20
21 ::math::complexnumbers::/ z1 z2
22
23 ::math::complexnumbers::conj z1
24
25 ::math::complexnumbers::real z1
26
27 ::math::complexnumbers::imag z1
28
29 ::math::complexnumbers::mod z1
30
31 ::math::complexnumbers::arg z1
32
33 ::math::complexnumbers::complex real imag
34
35 ::math::complexnumbers::tostring z1
36
37 ::math::complexnumbers::exp z1
38
39 ::math::complexnumbers::sin z1
40
41 ::math::complexnumbers::cos z1
42
43 ::math::complexnumbers::tan z1
44
45 ::math::complexnumbers::log z1
46
47 ::math::complexnumbers::sqrt z1
48
49 ::math::complexnumbers::pow z1 z2
50
51_________________________________________________________________
52
54 The mathematical module complexnumbers provides a straightforward
55 implementation of complex numbers in pure Tcl. The philosophy is that
56 the user knows he or she is dealing with complex numbers in an abstract
57 way and wants as high a performance as can be had within the limita‐
58 tions of an interpreted language.
59
60 Therefore the procedures defined in this package assume that the argu‐
61 ments are valid (representations of) "complex numbers", that is, lists
62 of two numbers defining the real and imaginary part of a complex number
63 (though this is a mere detail: rely on the complex command to construct
64 a valid number.)
65
66 Most procedures implement the basic arithmetic operations or elementary
67 functions whereas several others convert to and from different repre‐
68 sentations:
69
70 set z [complex 0 1]
71 puts "z = [tostring $z]"
72 puts "z**2 = [* $z $z]
73
74 would result in:
75
76 z = i
77 z**2 = -1
78
79
81 The package implements all or most basic operations and elementary
82 functions.
83
84 The arithmetic operations are:
85
86 ::math::complexnumbers::+ z1 z2
87 Add the two arguments and return the resulting complex number
88
89 z1 complex (in)
90 First argument in the summation
91
92 z2 complex (in)
93 Second argument in the summation
94
95
96 ::math::complexnumbers::- z1 z2
97 Subtract the second argument from the first and return the
98 resulting complex number. If there is only one argument, the
99 opposite of z1 is returned (i.e. -z1)
100
101 z1 complex (in)
102 First argument in the subtraction
103
104 z2 complex (in)
105 Second argument in the subtraction (optional)
106
107
108 ::math::complexnumbers::* z1 z2
109 Multiply the two arguments and return the resulting complex num‐
110 ber
111
112 z1 complex (in)
113 First argument in the multiplication
114
115 z2 complex (in)
116 Second argument in the multiplication
117
118
119 ::math::complexnumbers::/ z1 z2
120 Divide the first argument by the second and return the resulting
121 complex number
122
123 z1 complex (in)
124 First argument (numerator) in the division
125
126 z2 complex (in)
127 Second argument (denominator) in the division
128
129
130 ::math::complexnumbers::conj z1
131 Return the conjugate of the given complex number
132
133 z1 complex (in)
134 Complex number in question
135
136
137 Conversion/inquiry procedures:
138
139 ::math::complexnumbers::real z1
140 Return the real part of the given complex number
141
142 z1 complex (in)
143 Complex number in question
144
145
146 ::math::complexnumbers::imag z1
147 Return the imaginary part of the given complex number
148
149 z1 complex (in)
150 Complex number in question
151
152
153 ::math::complexnumbers::mod z1
154 Return the modulus of the given complex number
155
156 z1 complex (in)
157 Complex number in question
158
159
160 ::math::complexnumbers::arg z1
161 Return the argument ("angle" in radians) of the given complex
162 number
163
164 z1 complex (in)
165 Complex number in question
166
167
168 ::math::complexnumbers::complex real imag
169 Construct the complex number "real + imag*i" and return it
170
171 real float (in)
172 The real part of the new complex number
173
174 imag float (in)
175 The imaginary part of the new complex number
176
177
178 ::math::complexnumbers::tostring z1
179 Convert the complex number to the form "real + imag*i" and
180 return the string
181
182 complex float (in)
183 The complex number to be converted
184
185
186 Elementary functions:
187
188 ::math::complexnumbers::exp z1
189 Calculate the exponential for the given complex argument and
190 return the result
191
192 z1 complex (in)
193 The complex argument for the function
194
195
196 ::math::complexnumbers::sin z1
197 Calculate the sine function for the given complex argument and
198 return the result
199
200 z1 complex (in)
201 The complex argument for the function
202
203
204 ::math::complexnumbers::cos z1
205 Calculate the cosine function for the given complex argument and
206 return the result
207
208 z1 complex (in)
209 The complex argument for the function
210
211
212 ::math::complexnumbers::tan z1
213 Calculate the tangent function for the given complex argument
214 and return the result
215
216 z1 complex (in)
217 The complex argument for the function
218
219
220 ::math::complexnumbers::log z1
221 Calculate the (principle value of the) logarithm for the given
222 complex argument and return the result
223
224 z1 complex (in)
225 The complex argument for the function
226
227
228 ::math::complexnumbers::sqrt z1
229 Calculate the (principle value of the) square root for the given
230 complex argument and return the result
231
232 z1 complex (in)
233 The complex argument for the function
234
235
236 ::math::complexnumbers::pow z1 z2
237 Calculate "z1 to the power of z2" and return the result
238
239 z1 complex (in)
240 The complex number to be raised to a power
241
242 z2 complex (in)
243 The complex power to be used
244
246 complex numbers, math
247
249 Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
250
251
252
253
254math 1.0.2 math::complexnumbers(n)