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