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; |
|
205 atmp = a.inverse (); |
|
206 } |
|
207 else |
|
208 atmp = a; |
|
209 |
|
210 Matrix result (atmp); |
|
211 for (int i = 1; i < btmp; i++) |
|
212 result = result * atmp; |
|
213 |
|
214 retval = result; |
|
215 } |
1
|
216 } |
|
217 else |
|
218 { |
1567
|
219 EIG a_eig (a); |
|
220 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
|
221 ComplexMatrix Q (a_eig.eigenvectors ()); |
|
222 |
|
223 for (int i = 0; i < nr; i++) |
|
224 lambda.elem (i) = pow (lambda.elem (i), b); |
|
225 |
|
226 ComplexDiagMatrix D (lambda); |
|
227 |
|
228 retval = ComplexMatrix (Q * D * Q.inverse ()); |
|
229 } |
|
230 } |
1358
|
231 |
1567
|
232 return retval; |
|
233 } |
1
|
234 |
1567
|
235 // -*- 6 -*- |
|
236 tree_constant |
|
237 xpow (const Matrix& a, const Complex& b) |
|
238 { |
|
239 tree_constant retval; |
1
|
240 |
1567
|
241 int nr = a.rows (); |
|
242 int nc = a.columns (); |
|
243 |
|
244 if (nr == 0 || nc == 0 || nr != nc) |
|
245 { |
|
246 error ("for A^b, A must be square"); |
1
|
247 } |
|
248 else |
|
249 { |
|
250 EIG a_eig (a); |
|
251 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
|
252 ComplexMatrix Q (a_eig.eigenvectors ()); |
|
253 |
|
254 for (int i = 0; i < nr; i++) |
|
255 lambda.elem (i) = pow (lambda.elem (i), b); |
|
256 |
|
257 ComplexDiagMatrix D (lambda); |
|
258 |
1567
|
259 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
260 } |
|
261 |
|
262 return retval; |
|
263 } |
|
264 |
767
|
265 // -*- 7 -*- |
1
|
266 tree_constant |
164
|
267 xpow (const Complex& a, double b) |
1
|
268 { |
|
269 Complex result; |
1567
|
270 |
|
271 if (xisint (b)) |
|
272 result = pow (a, (int) b); |
|
273 else |
|
274 result = pow (a, b); |
|
275 |
|
276 return result; |
1
|
277 } |
|
278 |
767
|
279 // -*- 8 -*- |
1
|
280 tree_constant |
164
|
281 xpow (const Complex& a, const Matrix& b) |
1
|
282 { |
|
283 tree_constant retval; |
|
284 |
|
285 int nr = b.rows (); |
|
286 int nc = b.columns (); |
|
287 |
|
288 if (nr == 0 || nc == 0 || nr != nc) |
|
289 { |
|
290 error ("for x^A, A must be square"); |
|
291 } |
|
292 else |
|
293 { |
|
294 EIG b_eig (b); |
|
295 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
|
296 ComplexMatrix Q (b_eig.eigenvectors ()); |
|
297 |
|
298 for (int i = 0; i < nr; i++) |
|
299 { |
|
300 Complex elt = lambda.elem (i); |
|
301 if (imag (elt) == 0.0) |
|
302 lambda.elem (i) = pow (a, real (elt)); |
|
303 else |
|
304 lambda.elem (i) = pow (a, elt); |
|
305 } |
|
306 ComplexDiagMatrix D (lambda); |
|
307 |
1567
|
308 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
309 } |
|
310 |
|
311 return retval; |
|
312 } |
|
313 |
767
|
314 // -*- 9 -*- |
1
|
315 tree_constant |
164
|
316 xpow (const Complex& a, const Complex& b) |
1
|
317 { |
|
318 Complex result; |
|
319 result = pow (a, b); |
1567
|
320 return result; |
1
|
321 } |
|
322 |
767
|
323 // -*- 10 -*- |
1
|
324 tree_constant |
164
|
325 xpow (const Complex& a, const ComplexMatrix& b) |
1
|
326 { |
|
327 tree_constant retval; |
|
328 |
|
329 int nr = b.rows (); |
|
330 int nc = b.columns (); |
|
331 |
|
332 if (nr == 0 || nc == 0 || nr != nc) |
1567
|
333 { |
|
334 error ("for x^A, A must be square"); |
|
335 } |
1
|
336 else |
|
337 { |
|
338 EIG b_eig (b); |
|
339 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
|
340 ComplexMatrix Q (b_eig.eigenvectors ()); |
|
341 |
|
342 for (int i = 0; i < nr; i++) |
|
343 { |
|
344 Complex elt = lambda.elem (i); |
|
345 if (imag (elt) == 0.0) |
|
346 lambda.elem (i) = pow (a, real (elt)); |
|
347 else |
|
348 lambda.elem (i) = pow (a, elt); |
|
349 } |
|
350 ComplexDiagMatrix D (lambda); |
|
351 |
1567
|
352 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
353 } |
|
354 |
|
355 return retval; |
|
356 } |
|
357 |
767
|
358 // -*- 11 -*- |
1
|
359 tree_constant |
164
|
360 xpow (const ComplexMatrix& a, double b) |
1
|
361 { |
|
362 tree_constant retval; |
|
363 |
|
364 int nr = a.rows (); |
|
365 int nc = a.columns (); |
|
366 |
|
367 if (nr == 0 || nc == 0 || nr != nc) |
|
368 { |
|
369 error ("for A^b, A must be square"); |
|
370 } |
1567
|
371 else |
1
|
372 { |
1567
|
373 if ((int) b == b) |
1
|
374 { |
1567
|
375 int btmp = (int) b; |
|
376 if (btmp == 0) |
|
377 { |
|
378 retval = DiagMatrix (nr, nr, 1.0); |
|
379 } |
|
380 else |
|
381 { |
|
382 // Too much copying? |
|
383 // XXX FIXME XXX -- we shouldn't do this if the exponent is |
|
384 // large... |
|
385 |
|
386 ComplexMatrix atmp; |
|
387 if (btmp < 0) |
|
388 { |
|
389 btmp = -btmp; |
|
390 atmp = a.inverse (); |
|
391 } |
|
392 else |
|
393 atmp = a; |
|
394 |
|
395 ComplexMatrix result (atmp); |
|
396 for (int i = 1; i < btmp; i++) |
|
397 result = result * atmp; |
|
398 |
|
399 retval = result; |
|
400 } |
1
|
401 } |
|
402 else |
|
403 { |
1567
|
404 EIG a_eig (a); |
|
405 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
|
406 ComplexMatrix Q (a_eig.eigenvectors ()); |
|
407 |
|
408 for (int i = 0; i < nr; i++) |
|
409 lambda.elem (i) = pow (lambda.elem (i), b); |
|
410 |
|
411 ComplexDiagMatrix D (lambda); |
|
412 |
|
413 retval = ComplexMatrix (Q * D * Q.inverse ()); |
|
414 } |
|
415 } |
1358
|
416 |
1567
|
417 return retval; |
|
418 } |
1
|
419 |
1567
|
420 // -*- 12 -*- |
|
421 tree_constant |
|
422 xpow (const ComplexMatrix& a, const Complex& b) |
|
423 { |
|
424 tree_constant retval; |
1
|
425 |
1567
|
426 int nr = a.rows (); |
|
427 int nc = a.columns (); |
|
428 |
|
429 if (nr == 0 || nc == 0 || nr != nc) |
|
430 { |
|
431 error ("for A^b, A must be square"); |
1
|
432 } |
|
433 else |
|
434 { |
|
435 EIG a_eig (a); |
|
436 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
|
437 ComplexMatrix Q (a_eig.eigenvectors ()); |
|
438 |
|
439 for (int i = 0; i < nr; i++) |
|
440 lambda.elem (i) = pow (lambda.elem (i), b); |
|
441 |
|
442 ComplexDiagMatrix D (lambda); |
|
443 |
1567
|
444 retval = ComplexMatrix (Q * D * Q.inverse ()); |
1
|
445 } |
|
446 |
|
447 return retval; |
|
448 } |
|
449 |
767
|
450 // Safer pow functions that work elementwise for matrices. |
|
451 // |
|
452 // op2 \ op1: s m cs cm |
|
453 // +-- +---+---+----+----+ |
|
454 // scalar | | * | 3 | * | 9 | |
|
455 // +---+---+----+----+ |
|
456 // matrix | 1 | 4 | 7 | 10 | |
|
457 // +---+---+----+----+ |
|
458 // complex_scalar | * | 5 | * | 11 | |
|
459 // +---+---+----+----+ |
|
460 // complex_matrix | 2 | 6 | 8 | 12 | |
|
461 // +---+---+----+----+ |
|
462 // |
|
463 // * -> not needed. |
1
|
464 |
767
|
465 // -*- 1 -*- |
1
|
466 tree_constant |
164
|
467 elem_xpow (double a, const Matrix& b) |
1
|
468 { |
|
469 tree_constant retval; |
|
470 |
|
471 int nr = b.rows (); |
|
472 int nc = b.columns (); |
|
473 |
1358
|
474 // For now, assume the worst. |
|
475 |
1
|
476 if (a < 0.0) |
|
477 { |
|
478 Complex atmp (a); |
|
479 ComplexMatrix result (nr, nc); |
|
480 for (int j = 0; j < nc; j++) |
|
481 for (int i = 0; i < nr; i++) |
|
482 result.elem (i, j) = pow (atmp, b.elem (i, j)); |
|
483 |
1567
|
484 retval = result; |
1
|
485 } |
|
486 else |
|
487 { |
|
488 Matrix result (nr, nc); |
|
489 for (int j = 0; j < nc; j++) |
|
490 for (int i = 0; i < nr; i++) |
|
491 result.elem (i, j) = pow (a, b.elem (i, j)); |
|
492 |
1567
|
493 retval = result; |
1
|
494 } |
|
495 |
|
496 return retval; |
|
497 } |
|
498 |
767
|
499 // -*- 2 -*- |
1
|
500 tree_constant |
164
|
501 elem_xpow (double a, const ComplexMatrix& b) |
1
|
502 { |
|
503 int nr = b.rows (); |
|
504 int nc = b.columns (); |
|
505 |
|
506 ComplexMatrix result (nr, nc); |
|
507 for (int j = 0; j < nc; j++) |
|
508 for (int i = 0; i < nr; i++) |
|
509 result.elem (i, j) = pow (a, b.elem (i, j)); |
|
510 |
1567
|
511 return result; |
1
|
512 } |
|
513 |
767
|
514 // -*- 3 -*- |
1
|
515 tree_constant |
164
|
516 elem_xpow (const Matrix& a, double b) |
1
|
517 { |
|
518 tree_constant retval; |
|
519 |
|
520 int nr = a.rows (); |
|
521 int nc = a.columns (); |
|
522 |
|
523 if ((int) b != b && any_element_is_negative (a)) |
|
524 { |
|
525 ComplexMatrix result (nr, nc); |
|
526 for (int j = 0; j < nc; j++) |
|
527 for (int i = 0; i < nr; i++) |
|
528 { |
|
529 Complex atmp (a.elem (i, j)); |
|
530 result.elem (i, j) = pow (atmp, b); |
|
531 } |
|
532 |
1567
|
533 retval = result; |
1
|
534 } |
|
535 else |
|
536 { |
|
537 Matrix result (nr, nc); |
|
538 for (int j = 0; j < nc; j++) |
|
539 for (int i = 0; i < nr; i++) |
|
540 result.elem (i, j) = pow (a.elem (i, j), b); |
|
541 |
1567
|
542 retval = result; |
1
|
543 } |
|
544 |
|
545 return retval; |
|
546 } |
|
547 |
767
|
548 // -*- 4 -*- |
1
|
549 tree_constant |
164
|
550 elem_xpow (const Matrix& a, const Matrix& b) |
1
|
551 { |
1567
|
552 tree_constant retval; |
|
553 |
1
|
554 int nr = a.rows (); |
|
555 int nc = a.columns (); |
|
556 |
|
557 assert (nr == b.rows () && nc == b.columns ()); |
|
558 |
|
559 int convert_to_complex = 0; |
|
560 for (int j = 0; j < nc; j++) |
1321
|
561 for (int i = 0; i < nr; i++) |
1
|
562 { |
|
563 double atmp = a.elem (i, j); |
|
564 double btmp = b.elem (i, j); |
|
565 if (atmp < 0.0 && (int) btmp != btmp) |
|
566 { |
|
567 convert_to_complex = 1; |
|
568 goto done; |
|
569 } |
|
570 } |
|
571 |
|
572 done: |
|
573 |
|
574 if (convert_to_complex) |
|
575 { |
|
576 ComplexMatrix complex_result (nr, nc); |
|
577 |
1321
|
578 for (int j = 0; j < nc; j++) |
|
579 for (int i = 0; i < nr; i++) |
1
|
580 { |
|
581 Complex atmp (a.elem (i, j)); |
|
582 Complex btmp (b.elem (i, j)); |
|
583 complex_result.elem (i, j) = pow (atmp, btmp); |
|
584 } |
1567
|
585 |
|
586 retval = complex_result; |
1
|
587 } |
|
588 else |
|
589 { |
|
590 Matrix result (nr, nc); |
|
591 |
1321
|
592 for (int j = 0; j < nc; j++) |
|
593 for (int i = 0; i < nr; i++) |
1
|
594 result.elem (i, j) = pow (a.elem (i, j), b.elem (i, j)); |
|
595 |
1567
|
596 retval = result; |
1
|
597 } |
1567
|
598 |
|
599 return retval; |
1
|
600 } |
|
601 |
767
|
602 // -*- 5 -*- |
1
|
603 tree_constant |
164
|
604 elem_xpow (const Matrix& a, const Complex& b) |
1
|
605 { |
|
606 int nr = a.rows (); |
|
607 int nc = a.columns (); |
|
608 |
|
609 ComplexMatrix result (nr, nc); |
|
610 for (int j = 0; j < nc; j++) |
|
611 for (int i = 0; i < nr; i++) |
|
612 result.elem (i, j) = pow (a.elem (i, j), b); |
|
613 |
1567
|
614 return result; |
1
|
615 } |
|
616 |
767
|
617 // -*- 6 -*- |
1
|
618 tree_constant |
164
|
619 elem_xpow (const Matrix& a, const ComplexMatrix& b) |
1
|
620 { |
|
621 int nr = a.rows (); |
|
622 int nc = a.columns (); |
|
623 |
|
624 assert (nr == b.rows () && nc == b.columns ()); |
|
625 |
|
626 ComplexMatrix result (nr, nc); |
|
627 for (int j = 0; j < nc; j++) |
|
628 for (int i = 0; i < nr; i++) |
|
629 result.elem (i, j) = pow (a.elem (i, j), b.elem (i, j)); |
|
630 |
1567
|
631 return result; |
1
|
632 } |
|
633 |
767
|
634 // -*- 7 -*- |
1
|
635 tree_constant |
164
|
636 elem_xpow (const Complex& a, const Matrix& b) |
1
|
637 { |
|
638 int nr = b.rows (); |
|
639 int nc = b.columns (); |
|
640 |
|
641 ComplexMatrix result (nr, nc); |
|
642 for (int j = 0; j < nc; j++) |
|
643 for (int i = 0; i < nr; i++) |
1567
|
644 { |
|
645 double btmp = b.elem (i, j); |
|
646 if (xisint (btmp)) |
|
647 result.elem (i, j) = pow (a, (int) btmp); |
|
648 else |
|
649 result.elem (i, j) = pow (a, btmp); |
|
650 } |
1
|
651 |
1567
|
652 return result; |
1
|
653 } |
|
654 |
767
|
655 // -*- 8 -*- |
1
|
656 tree_constant |
164
|
657 elem_xpow (const Complex& a, const ComplexMatrix& b) |
1
|
658 { |
|
659 int nr = b.rows (); |
|
660 int nc = b.columns (); |
|
661 |
|
662 ComplexMatrix result (nr, nc); |
|
663 for (int j = 0; j < nc; j++) |
|
664 for (int i = 0; i < nr; i++) |
|
665 result.elem (i, j) = pow (a, b.elem (i, j)); |
|
666 |
1567
|
667 return result; |
1
|
668 } |
|
669 |
767
|
670 // -*- 9 -*- |
1
|
671 tree_constant |
164
|
672 elem_xpow (const ComplexMatrix& a, double b) |
1
|
673 { |
|
674 int nr = a.rows (); |
|
675 int nc = a.columns (); |
|
676 |
|
677 ComplexMatrix result (nr, nc); |
|
678 |
1567
|
679 if (xisint (b)) |
|
680 { |
|
681 for (int j = 0; j < nc; j++) |
|
682 for (int i = 0; i < nr; i++) |
|
683 result.elem (i, j) = pow (a.elem (i, j), (int) b); |
|
684 } |
|
685 else |
|
686 { |
|
687 for (int j = 0; j < nc; j++) |
|
688 for (int i = 0; i < nr; i++) |
|
689 result.elem (i, j) = pow (a.elem (i, j), b); |
|
690 } |
|
691 |
|
692 return result; |
1
|
693 } |
|
694 |
767
|
695 // -*- 10 -*- |
1
|
696 tree_constant |
164
|
697 elem_xpow (const ComplexMatrix& a, const Matrix& b) |
1
|
698 { |
|
699 int nr = a.rows (); |
|
700 int nc = a.columns (); |
|
701 |
|
702 assert (nr == b.rows () && nc == b.columns ()); |
|
703 |
|
704 ComplexMatrix result (nr, nc); |
|
705 for (int j = 0; j < nc; j++) |
|
706 for (int i = 0; i < nr; i++) |
1567
|
707 { |
|
708 double btmp = b.elem (i, j); |
|
709 if (xisint (btmp)) |
|
710 result.elem (i, j) = pow (a.elem (i, j), (int) btmp); |
|
711 else |
|
712 result.elem (i, j) = pow (a.elem (i, j), btmp); |
|
713 } |
1
|
714 |
1567
|
715 return result; |
1
|
716 } |
|
717 |
767
|
718 // -*- 11 -*- |
1
|
719 tree_constant |
164
|
720 elem_xpow (const ComplexMatrix& a, const Complex& b) |
1
|
721 { |
|
722 int nr = a.rows (); |
|
723 int nc = a.columns (); |
|
724 |
|
725 ComplexMatrix result (nr, nc); |
|
726 for (int j = 0; j < nc; j++) |
|
727 for (int i = 0; i < nr; i++) |
|
728 result.elem (i, j) = pow (a.elem (i, j), b); |
|
729 |
1567
|
730 return result; |
1
|
731 } |
|
732 |
767
|
733 // -*- 12 -*- |
1
|
734 tree_constant |
164
|
735 elem_xpow (const ComplexMatrix& a, const ComplexMatrix& b) |
1
|
736 { |
|
737 int nr = a.rows (); |
|
738 int nc = a.columns (); |
|
739 |
|
740 ComplexMatrix result (nr, nc); |
|
741 |
|
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.elem (i, j)); |
|
745 |
1567
|
746 return result; |
1
|
747 } |
|
748 |
|
749 /* |
|
750 ;;; Local Variables: *** |
|
751 ;;; mode: C++ *** |
|
752 ;;; page-delimiter: "^/\\*" *** |
|
753 ;;; End: *** |
|
754 */ |