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