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