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