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