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