1
|
1 // xpow.cc -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1
|
26 #endif |
|
27 |
1343
|
28 #include <cassert> |
1580
|
29 #include <climits> |
1343
|
30 |
1352
|
31 #include "CColVector.h" |
453
|
32 #include "CDiagMatrix.h" |
1352
|
33 #include "CMatrix.h" |
453
|
34 #include "EIG.h" |
1352
|
35 #include "dDiagMatrix.h" |
|
36 #include "dMatrix.h" |
1651
|
37 #include "oct-cmplx.h" |
1352
|
38 |
|
39 #include "error.h" |
164
|
40 #include "tree-const.h" |
1567
|
41 #include "utils.h" |
1352
|
42 #include "xpow.h" |
1
|
43 |
|
44 // This function also appears in tree-const.cc. Maybe it should be a |
|
45 // member function of the Matrix class. |
|
46 |
|
47 static int |
|
48 any_element_is_negative (const Matrix& a) |
|
49 { |
|
50 int nr = a.rows (); |
|
51 int nc = a.columns (); |
|
52 for (int j = 0; j < nc; j++) |
|
53 for (int i = 0; i < nr; i++) |
|
54 if (a.elem (i, j) < 0.0) |
|
55 return 1; |
|
56 return 0; |
|
57 } |
|
58 |
1567
|
59 static inline int |
|
60 xisint (double x) |
|
61 { |
|
62 return (D_NINT (x) == x |
|
63 && ((x >= 0 && x < INT_MAX) |
|
64 || (x <= 0 && x > INT_MIN))); |
|
65 } |
|
66 |
767
|
67 // Safer pow functions. |
|
68 // |
|
69 // op2 \ op1: s m cs cm |
|
70 // +-- +---+---+----+----+ |
|
71 // scalar | | 1 | 5 | 7 | 11 | |
|
72 // +---+---+----+----+ |
|
73 // matrix | 2 | E | 8 | E | |
|
74 // +---+---+----+----+ |
|
75 // complex_scalar | 3 | 6 | 9 | 12 | |
|
76 // +---+---+----+----+ |
|
77 // complex_matrix | 4 | E | 10 | E | |
|
78 // +---+---+----+----+ |
|
79 // |
|
80 // E -> error, trapped in arith-ops.cc. |
1
|
81 |
767
|
82 // -*- 1 -*- |
1
|
83 tree_constant |
|
84 xpow (double a, double b) |
|
85 { |
|
86 if (a < 0.0 && (int) b != b) |
|
87 { |
|
88 Complex atmp (a); |
1567
|
89 return pow (atmp, b); |
1
|
90 } |
|
91 else |
1567
|
92 return pow (a, b); |
1
|
93 } |
|
94 |
767
|
95 // -*- 2 -*- |
1
|
96 tree_constant |
164
|
97 xpow (double a, const Matrix& b) |
1
|
98 { |
|
99 tree_constant retval; |
|
100 |
|
101 int nr = b.rows (); |
|
102 int nc = b.columns (); |
|
103 |
|
104 if (nr == 0 || nc == 0 || nr != nc) |
|
105 error ("for x^A, A must be square"); |
|
106 else |
|
107 { |
|
108 EIG b_eig (b); |
|
109 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
|
110 ComplexMatrix Q (b_eig.eigenvectors ()); |
|
111 |
|
112 for (int i = 0; i < nr; i++) |
|
113 { |
|
114 Complex elt = lambda.elem (i); |
|
115 if (imag (elt) == 0.0) |
|
116 lambda.elem (i) = pow (a, real (elt)); |
|
117 else |
|
118 lambda.elem (i) = pow (a, elt); |
|
119 } |
|
120 ComplexDiagMatrix D (lambda); |
|
121 |
1567
|
122 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
123 } |
|
124 |
|
125 return retval; |
|
126 } |
|
127 |
767
|
128 // -*- 3 -*- |
1
|
129 tree_constant |
164
|
130 xpow (double a, const Complex& b) |
1
|
131 { |
|
132 Complex result; |
|
133 Complex atmp (a); |
|
134 result = pow (atmp, b); |
1567
|
135 return result; |
1
|
136 } |
|
137 |
767
|
138 // -*- 4 -*- |
1
|
139 tree_constant |
164
|
140 xpow (double a, const ComplexMatrix& b) |
1
|
141 { |
|
142 tree_constant retval; |
|
143 |
|
144 int nr = b.rows (); |
|
145 int nc = b.columns (); |
|
146 |
|
147 if (nr == 0 || nc == 0 || nr != nc) |
1567
|
148 { |
|
149 error ("for x^A, A must be square"); |
|
150 } |
1
|
151 else |
|
152 { |
|
153 EIG b_eig (b); |
|
154 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
|
155 ComplexMatrix Q (b_eig.eigenvectors ()); |
|
156 |
|
157 for (int i = 0; i < nr; i++) |
|
158 { |
|
159 Complex elt = lambda.elem (i); |
|
160 if (imag (elt) == 0.0) |
|
161 lambda.elem (i) = pow (a, real (elt)); |
|
162 else |
|
163 lambda.elem (i) = pow (a, elt); |
|
164 } |
|
165 ComplexDiagMatrix D (lambda); |
|
166 |
1567
|
167 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
168 } |
|
169 |
|
170 return retval; |
|
171 } |
|
172 |
767
|
173 // -*- 5 -*- |
1
|
174 tree_constant |
164
|
175 xpow (const Matrix& a, double b) |
1
|
176 { |
|
177 tree_constant retval; |
|
178 |
|
179 int nr = a.rows (); |
|
180 int nc = a.columns (); |
|
181 |
|
182 if (nr == 0 || nc == 0 || nr != nc) |
|
183 { |
|
184 error ("for A^b, A must be square"); |
|
185 } |
1567
|
186 else |
1
|
187 { |
1567
|
188 if ((int) b == b) |
1
|
189 { |
1567
|
190 int btmp = (int) b; |
|
191 if (btmp == 0) |
|
192 { |
|
193 retval = DiagMatrix (nr, nr, 1.0); |
|
194 } |
|
195 else |
|
196 { |
|
197 // Too much copying? |
|
198 // XXX FIXME XXX -- we shouldn't do this if the exponent is |
|
199 // large... |
|
200 |
|
201 Matrix atmp; |
|
202 if (btmp < 0) |
|
203 { |
|
204 btmp = -btmp; |
1655
|
205 |
|
206 int info; |
|
207 double rcond = 0.0; |
|
208 |
|
209 atmp = a.inverse (info, rcond); |
|
210 |
|
211 if (info == -1) |
|
212 warning ("inverse: matrix singular to machine\ |
|
213 precision, rcond = %g", rcond); |
1567
|
214 } |
|
215 else |
|
216 atmp = a; |
|
217 |
|
218 Matrix result (atmp); |
|
219 for (int i = 1; i < btmp; i++) |
|
220 result = result * atmp; |
|
221 |
|
222 retval = result; |
|
223 } |
1
|
224 } |
|
225 else |
|
226 { |
1567
|
227 EIG a_eig (a); |
|
228 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
|
229 ComplexMatrix Q (a_eig.eigenvectors ()); |
|
230 |
|
231 for (int i = 0; i < nr; i++) |
|
232 lambda.elem (i) = pow (lambda.elem (i), b); |
|
233 |
|
234 ComplexDiagMatrix D (lambda); |
|
235 |
|
236 retval = ComplexMatrix (Q * D * Q.inverse ()); |
|
237 } |
|
238 } |
1358
|
239 |
1567
|
240 return retval; |
|
241 } |
1
|
242 |
1567
|
243 // -*- 6 -*- |
|
244 tree_constant |
|
245 xpow (const Matrix& a, const Complex& b) |
|
246 { |
|
247 tree_constant retval; |
1
|
248 |
1567
|
249 int nr = a.rows (); |
|
250 int nc = a.columns (); |
|
251 |
|
252 if (nr == 0 || nc == 0 || nr != nc) |
|
253 { |
|
254 error ("for A^b, A must be square"); |
1
|
255 } |
|
256 else |
|
257 { |
|
258 EIG a_eig (a); |
|
259 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
|
260 ComplexMatrix Q (a_eig.eigenvectors ()); |
|
261 |
|
262 for (int i = 0; i < nr; i++) |
|
263 lambda.elem (i) = pow (lambda.elem (i), b); |
|
264 |
|
265 ComplexDiagMatrix D (lambda); |
|
266 |
1567
|
267 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
268 } |
|
269 |
|
270 return retval; |
|
271 } |
|
272 |
767
|
273 // -*- 7 -*- |
1
|
274 tree_constant |
164
|
275 xpow (const Complex& a, double b) |
1
|
276 { |
|
277 Complex result; |
1567
|
278 |
|
279 if (xisint (b)) |
|
280 result = pow (a, (int) b); |
|
281 else |
|
282 result = pow (a, b); |
|
283 |
|
284 return result; |
1
|
285 } |
|
286 |
767
|
287 // -*- 8 -*- |
1
|
288 tree_constant |
164
|
289 xpow (const Complex& a, const Matrix& b) |
1
|
290 { |
|
291 tree_constant retval; |
|
292 |
|
293 int nr = b.rows (); |
|
294 int nc = b.columns (); |
|
295 |
|
296 if (nr == 0 || nc == 0 || nr != nc) |
|
297 { |
|
298 error ("for x^A, A must be square"); |
|
299 } |
|
300 else |
|
301 { |
|
302 EIG b_eig (b); |
|
303 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
|
304 ComplexMatrix Q (b_eig.eigenvectors ()); |
|
305 |
|
306 for (int i = 0; i < nr; i++) |
|
307 { |
|
308 Complex elt = lambda.elem (i); |
|
309 if (imag (elt) == 0.0) |
|
310 lambda.elem (i) = pow (a, real (elt)); |
|
311 else |
|
312 lambda.elem (i) = pow (a, elt); |
|
313 } |
|
314 ComplexDiagMatrix D (lambda); |
|
315 |
1567
|
316 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
317 } |
|
318 |
|
319 return retval; |
|
320 } |
|
321 |
767
|
322 // -*- 9 -*- |
1
|
323 tree_constant |
164
|
324 xpow (const Complex& a, const Complex& b) |
1
|
325 { |
|
326 Complex result; |
|
327 result = pow (a, b); |
1567
|
328 return result; |
1
|
329 } |
|
330 |
767
|
331 // -*- 10 -*- |
1
|
332 tree_constant |
164
|
333 xpow (const Complex& a, const ComplexMatrix& b) |
1
|
334 { |
|
335 tree_constant retval; |
|
336 |
|
337 int nr = b.rows (); |
|
338 int nc = b.columns (); |
|
339 |
|
340 if (nr == 0 || nc == 0 || nr != nc) |
1567
|
341 { |
|
342 error ("for x^A, A must be square"); |
|
343 } |
1
|
344 else |
|
345 { |
|
346 EIG b_eig (b); |
|
347 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
|
348 ComplexMatrix Q (b_eig.eigenvectors ()); |
|
349 |
|
350 for (int i = 0; i < nr; i++) |
|
351 { |
|
352 Complex elt = lambda.elem (i); |
|
353 if (imag (elt) == 0.0) |
|
354 lambda.elem (i) = pow (a, real (elt)); |
|
355 else |
|
356 lambda.elem (i) = pow (a, elt); |
|
357 } |
|
358 ComplexDiagMatrix D (lambda); |
|
359 |
1567
|
360 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
361 } |
|
362 |
|
363 return retval; |
|
364 } |
|
365 |
767
|
366 // -*- 11 -*- |
1
|
367 tree_constant |
164
|
368 xpow (const ComplexMatrix& a, double b) |
1
|
369 { |
|
370 tree_constant retval; |
|
371 |
|
372 int nr = a.rows (); |
|
373 int nc = a.columns (); |
|
374 |
|
375 if (nr == 0 || nc == 0 || nr != nc) |
|
376 { |
|
377 error ("for A^b, A must be square"); |
|
378 } |
1567
|
379 else |
1
|
380 { |
1567
|
381 if ((int) b == b) |
1
|
382 { |
1567
|
383 int btmp = (int) b; |
|
384 if (btmp == 0) |
|
385 { |
|
386 retval = DiagMatrix (nr, nr, 1.0); |
|
387 } |
|
388 else |
|
389 { |
|
390 // Too much copying? |
|
391 // XXX FIXME XXX -- we shouldn't do this if the exponent is |
|
392 // large... |
|
393 |
|
394 ComplexMatrix atmp; |
|
395 if (btmp < 0) |
|
396 { |
|
397 btmp = -btmp; |
1655
|
398 |
|
399 int info; |
|
400 double rcond = 0.0; |
|
401 |
|
402 atmp = a.inverse (info, rcond); |
|
403 |
|
404 if (info == -1) |
|
405 warning ("inverse: matrix singular to machine\ |
|
406 precision, rcond = %g", rcond); |
1567
|
407 } |
|
408 else |
|
409 atmp = a; |
|
410 |
|
411 ComplexMatrix result (atmp); |
|
412 for (int i = 1; i < btmp; i++) |
|
413 result = result * atmp; |
|
414 |
|
415 retval = result; |
|
416 } |
1
|
417 } |
|
418 else |
|
419 { |
1567
|
420 EIG a_eig (a); |
|
421 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
|
422 ComplexMatrix Q (a_eig.eigenvectors ()); |
|
423 |
|
424 for (int i = 0; i < nr; i++) |
|
425 lambda.elem (i) = pow (lambda.elem (i), b); |
|
426 |
|
427 ComplexDiagMatrix D (lambda); |
|
428 |
|
429 retval = ComplexMatrix (Q * D * Q.inverse ()); |
|
430 } |
|
431 } |
1358
|
432 |
1567
|
433 return retval; |
|
434 } |
1
|
435 |
1567
|
436 // -*- 12 -*- |
|
437 tree_constant |
|
438 xpow (const ComplexMatrix& a, const Complex& b) |
|
439 { |
|
440 tree_constant retval; |
1
|
441 |
1567
|
442 int nr = a.rows (); |
|
443 int nc = a.columns (); |
|
444 |
|
445 if (nr == 0 || nc == 0 || nr != nc) |
|
446 { |
|
447 error ("for A^b, A must be square"); |
1
|
448 } |
|
449 else |
|
450 { |
|
451 EIG a_eig (a); |
|
452 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
|
453 ComplexMatrix Q (a_eig.eigenvectors ()); |
|
454 |
|
455 for (int i = 0; i < nr; i++) |
|
456 lambda.elem (i) = pow (lambda.elem (i), b); |
|
457 |
|
458 ComplexDiagMatrix D (lambda); |
|
459 |
1567
|
460 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
461 } |
|
462 |
|
463 return retval; |
|
464 } |
|
465 |
767
|
466 // Safer pow functions that work elementwise for matrices. |
|
467 // |
|
468 // op2 \ op1: s m cs cm |
|
469 // +-- +---+---+----+----+ |
|
470 // scalar | | * | 3 | * | 9 | |
|
471 // +---+---+----+----+ |
|
472 // matrix | 1 | 4 | 7 | 10 | |
|
473 // +---+---+----+----+ |
|
474 // complex_scalar | * | 5 | * | 11 | |
|
475 // +---+---+----+----+ |
|
476 // complex_matrix | 2 | 6 | 8 | 12 | |
|
477 // +---+---+----+----+ |
|
478 // |
|
479 // * -> not needed. |
1
|
480 |
767
|
481 // -*- 1 -*- |
1
|
482 tree_constant |
164
|
483 elem_xpow (double a, const Matrix& b) |
1
|
484 { |
|
485 tree_constant retval; |
|
486 |
|
487 int nr = b.rows (); |
|
488 int nc = b.columns (); |
|
489 |
1358
|
490 // For now, assume the worst. |
|
491 |
1
|
492 if (a < 0.0) |
|
493 { |
|
494 Complex atmp (a); |
|
495 ComplexMatrix result (nr, nc); |
|
496 for (int j = 0; j < nc; j++) |
|
497 for (int i = 0; i < nr; i++) |
|
498 result.elem (i, j) = pow (atmp, b.elem (i, j)); |
|
499 |
1567
|
500 retval = result; |
1
|
501 } |
|
502 else |
|
503 { |
|
504 Matrix result (nr, nc); |
|
505 for (int j = 0; j < nc; j++) |
|
506 for (int i = 0; i < nr; i++) |
|
507 result.elem (i, j) = pow (a, b.elem (i, j)); |
|
508 |
1567
|
509 retval = result; |
1
|
510 } |
|
511 |
|
512 return retval; |
|
513 } |
|
514 |
767
|
515 // -*- 2 -*- |
1
|
516 tree_constant |
164
|
517 elem_xpow (double a, const ComplexMatrix& b) |
1
|
518 { |
|
519 int nr = b.rows (); |
|
520 int nc = b.columns (); |
|
521 |
|
522 ComplexMatrix result (nr, nc); |
|
523 for (int j = 0; j < nc; j++) |
|
524 for (int i = 0; i < nr; i++) |
|
525 result.elem (i, j) = pow (a, b.elem (i, j)); |
|
526 |
1567
|
527 return result; |
1
|
528 } |
|
529 |
767
|
530 // -*- 3 -*- |
1
|
531 tree_constant |
164
|
532 elem_xpow (const Matrix& a, double b) |
1
|
533 { |
|
534 tree_constant retval; |
|
535 |
|
536 int nr = a.rows (); |
|
537 int nc = a.columns (); |
|
538 |
|
539 if ((int) b != b && any_element_is_negative (a)) |
|
540 { |
|
541 ComplexMatrix result (nr, nc); |
|
542 for (int j = 0; j < nc; j++) |
|
543 for (int i = 0; i < nr; i++) |
|
544 { |
|
545 Complex atmp (a.elem (i, j)); |
|
546 result.elem (i, j) = pow (atmp, b); |
|
547 } |
|
548 |
1567
|
549 retval = result; |
1
|
550 } |
|
551 else |
|
552 { |
|
553 Matrix result (nr, nc); |
|
554 for (int j = 0; j < nc; j++) |
|
555 for (int i = 0; i < nr; i++) |
|
556 result.elem (i, j) = pow (a.elem (i, j), b); |
|
557 |
1567
|
558 retval = result; |
1
|
559 } |
|
560 |
|
561 return retval; |
|
562 } |
|
563 |
767
|
564 // -*- 4 -*- |
1
|
565 tree_constant |
164
|
566 elem_xpow (const Matrix& a, const Matrix& b) |
1
|
567 { |
1567
|
568 tree_constant retval; |
|
569 |
1
|
570 int nr = a.rows (); |
|
571 int nc = a.columns (); |
|
572 |
|
573 assert (nr == b.rows () && nc == b.columns ()); |
|
574 |
|
575 int convert_to_complex = 0; |
|
576 for (int j = 0; j < nc; j++) |
1321
|
577 for (int i = 0; i < nr; i++) |
1
|
578 { |
|
579 double atmp = a.elem (i, j); |
|
580 double btmp = b.elem (i, j); |
|
581 if (atmp < 0.0 && (int) btmp != btmp) |
|
582 { |
|
583 convert_to_complex = 1; |
|
584 goto done; |
|
585 } |
|
586 } |
|
587 |
|
588 done: |
|
589 |
|
590 if (convert_to_complex) |
|
591 { |
|
592 ComplexMatrix complex_result (nr, nc); |
|
593 |
1321
|
594 for (int j = 0; j < nc; j++) |
|
595 for (int i = 0; i < nr; i++) |
1
|
596 { |
|
597 Complex atmp (a.elem (i, j)); |
|
598 Complex btmp (b.elem (i, j)); |
|
599 complex_result.elem (i, j) = pow (atmp, btmp); |
|
600 } |
1567
|
601 |
|
602 retval = complex_result; |
1
|
603 } |
|
604 else |
|
605 { |
|
606 Matrix result (nr, nc); |
|
607 |
1321
|
608 for (int j = 0; j < nc; j++) |
|
609 for (int i = 0; i < nr; i++) |
1
|
610 result.elem (i, j) = pow (a.elem (i, j), b.elem (i, j)); |
|
611 |
1567
|
612 retval = result; |
1
|
613 } |
1567
|
614 |
|
615 return retval; |
1
|
616 } |
|
617 |
767
|
618 // -*- 5 -*- |
1
|
619 tree_constant |
164
|
620 elem_xpow (const Matrix& a, const Complex& b) |
1
|
621 { |
|
622 int nr = a.rows (); |
|
623 int nc = a.columns (); |
|
624 |
|
625 ComplexMatrix result (nr, nc); |
|
626 for (int j = 0; j < nc; j++) |
|
627 for (int i = 0; i < nr; i++) |
|
628 result.elem (i, j) = pow (a.elem (i, j), b); |
|
629 |
1567
|
630 return result; |
1
|
631 } |
|
632 |
767
|
633 // -*- 6 -*- |
1
|
634 tree_constant |
164
|
635 elem_xpow (const Matrix& a, const ComplexMatrix& b) |
1
|
636 { |
|
637 int nr = a.rows (); |
|
638 int nc = a.columns (); |
|
639 |
|
640 assert (nr == b.rows () && nc == b.columns ()); |
|
641 |
|
642 ComplexMatrix result (nr, nc); |
|
643 for (int j = 0; j < nc; j++) |
|
644 for (int i = 0; i < nr; i++) |
|
645 result.elem (i, j) = pow (a.elem (i, j), b.elem (i, j)); |
|
646 |
1567
|
647 return result; |
1
|
648 } |
|
649 |
767
|
650 // -*- 7 -*- |
1
|
651 tree_constant |
164
|
652 elem_xpow (const Complex& a, const Matrix& b) |
1
|
653 { |
|
654 int nr = b.rows (); |
|
655 int nc = b.columns (); |
|
656 |
|
657 ComplexMatrix result (nr, nc); |
|
658 for (int j = 0; j < nc; j++) |
|
659 for (int i = 0; i < nr; i++) |
1567
|
660 { |
|
661 double btmp = b.elem (i, j); |
|
662 if (xisint (btmp)) |
|
663 result.elem (i, j) = pow (a, (int) btmp); |
|
664 else |
|
665 result.elem (i, j) = pow (a, btmp); |
|
666 } |
1
|
667 |
1567
|
668 return result; |
1
|
669 } |
|
670 |
767
|
671 // -*- 8 -*- |
1
|
672 tree_constant |
164
|
673 elem_xpow (const Complex& a, const ComplexMatrix& b) |
1
|
674 { |
|
675 int nr = b.rows (); |
|
676 int nc = b.columns (); |
|
677 |
|
678 ComplexMatrix result (nr, nc); |
|
679 for (int j = 0; j < nc; j++) |
|
680 for (int i = 0; i < nr; i++) |
|
681 result.elem (i, j) = pow (a, b.elem (i, j)); |
|
682 |
1567
|
683 return result; |
1
|
684 } |
|
685 |
767
|
686 // -*- 9 -*- |
1
|
687 tree_constant |
164
|
688 elem_xpow (const ComplexMatrix& a, double b) |
1
|
689 { |
|
690 int nr = a.rows (); |
|
691 int nc = a.columns (); |
|
692 |
|
693 ComplexMatrix result (nr, nc); |
|
694 |
1567
|
695 if (xisint (b)) |
|
696 { |
|
697 for (int j = 0; j < nc; j++) |
|
698 for (int i = 0; i < nr; i++) |
|
699 result.elem (i, j) = pow (a.elem (i, j), (int) b); |
|
700 } |
|
701 else |
|
702 { |
|
703 for (int j = 0; j < nc; j++) |
|
704 for (int i = 0; i < nr; i++) |
|
705 result.elem (i, j) = pow (a.elem (i, j), b); |
|
706 } |
|
707 |
|
708 return result; |
1
|
709 } |
|
710 |
767
|
711 // -*- 10 -*- |
1
|
712 tree_constant |
164
|
713 elem_xpow (const ComplexMatrix& a, const Matrix& b) |
1
|
714 { |
|
715 int nr = a.rows (); |
|
716 int nc = a.columns (); |
|
717 |
|
718 assert (nr == b.rows () && nc == b.columns ()); |
|
719 |
|
720 ComplexMatrix result (nr, nc); |
|
721 for (int j = 0; j < nc; j++) |
|
722 for (int i = 0; i < nr; i++) |
1567
|
723 { |
|
724 double btmp = b.elem (i, j); |
|
725 if (xisint (btmp)) |
|
726 result.elem (i, j) = pow (a.elem (i, j), (int) btmp); |
|
727 else |
|
728 result.elem (i, j) = pow (a.elem (i, j), btmp); |
|
729 } |
1
|
730 |
1567
|
731 return result; |
1
|
732 } |
|
733 |
767
|
734 // -*- 11 -*- |
1
|
735 tree_constant |
164
|
736 elem_xpow (const ComplexMatrix& a, const Complex& b) |
1
|
737 { |
|
738 int nr = a.rows (); |
|
739 int nc = a.columns (); |
|
740 |
|
741 ComplexMatrix result (nr, nc); |
|
742 for (int j = 0; j < nc; j++) |
|
743 for (int i = 0; i < nr; i++) |
|
744 result.elem (i, j) = pow (a.elem (i, j), b); |
|
745 |
1567
|
746 return result; |
1
|
747 } |
|
748 |
767
|
749 // -*- 12 -*- |
1
|
750 tree_constant |
164
|
751 elem_xpow (const ComplexMatrix& a, const ComplexMatrix& b) |
1
|
752 { |
|
753 int nr = a.rows (); |
|
754 int nc = a.columns (); |
|
755 |
|
756 ComplexMatrix result (nr, nc); |
|
757 |
|
758 for (int j = 0; j < nc; j++) |
|
759 for (int i = 0; i < nr; i++) |
|
760 result.elem (i, j) = pow (a.elem (i, j), b.elem (i, j)); |
|
761 |
1567
|
762 return result; |
1
|
763 } |
|
764 |
|
765 /* |
|
766 ;;; Local Variables: *** |
|
767 ;;; mode: C++ *** |
|
768 ;;; page-delimiter: "^/\\*" *** |
|
769 ;;; End: *** |
|
770 */ |