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" |
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 |
3162
|
449 // XXX FIXME XXX -- these functions need to be fixed so that things |
|
450 // like |
|
451 // |
|
452 // a = -1; b = [ 0, 0.5, 1 ]; r = a .^ b |
|
453 // |
|
454 // and |
|
455 // |
|
456 // a = -1; b = [ 0, 0.5, 1 ]; for i = 1:3, r(i) = a .^ b(i), end |
|
457 // |
|
458 // produce identical results. Also, it would be nice if -1^0.5 |
|
459 // produced a pure imaginary result instead of a complex number with a |
|
460 // small real part. But perhaps that's really a problem with the math |
|
461 // library... |
|
462 |
767
|
463 // -*- 1 -*- |
2086
|
464 octave_value |
164
|
465 elem_xpow (double a, const Matrix& b) |
1
|
466 { |
2086
|
467 octave_value retval; |
1
|
468 |
|
469 int nr = b.rows (); |
2365
|
470 int nc = b.cols (); |
1
|
471 |
3162
|
472 double d1, d2; |
1358
|
473 |
3162
|
474 if (a < 0.0 && ! b.all_integers (d1, d2)) |
1
|
475 { |
|
476 Complex atmp (a); |
|
477 ComplexMatrix result (nr, nc); |
|
478 for (int j = 0; j < nc; j++) |
|
479 for (int i = 0; i < nr; i++) |
2305
|
480 result (i, j) = pow (atmp, b (i, j)); |
1
|
481 |
1567
|
482 retval = result; |
1
|
483 } |
|
484 else |
|
485 { |
|
486 Matrix result (nr, nc); |
|
487 for (int j = 0; j < nc; j++) |
|
488 for (int i = 0; i < nr; i++) |
2305
|
489 result (i, j) = pow (a, b (i, j)); |
1
|
490 |
1567
|
491 retval = result; |
1
|
492 } |
|
493 |
|
494 return retval; |
|
495 } |
|
496 |
767
|
497 // -*- 2 -*- |
2086
|
498 octave_value |
164
|
499 elem_xpow (double a, const ComplexMatrix& b) |
1
|
500 { |
|
501 int nr = b.rows (); |
2365
|
502 int nc = b.cols (); |
1
|
503 |
|
504 ComplexMatrix result (nr, nc); |
3125
|
505 Complex atmp (a); |
1
|
506 for (int j = 0; j < nc; j++) |
|
507 for (int i = 0; i < nr; i++) |
3125
|
508 result (i, j) = pow (atmp, b (i, j)); |
1
|
509 |
1567
|
510 return result; |
1
|
511 } |
|
512 |
767
|
513 // -*- 3 -*- |
2086
|
514 octave_value |
164
|
515 elem_xpow (const Matrix& a, double b) |
1
|
516 { |
2086
|
517 octave_value retval; |
1
|
518 |
|
519 int nr = a.rows (); |
2365
|
520 int nc = a.cols (); |
1
|
521 |
2800
|
522 if (static_cast<int> (b) != b && a.any_element_is_negative ()) |
1
|
523 { |
|
524 ComplexMatrix result (nr, nc); |
|
525 for (int j = 0; j < nc; j++) |
|
526 for (int i = 0; i < nr; i++) |
|
527 { |
2305
|
528 Complex atmp (a (i, j)); |
|
529 result (i, j) = pow (atmp, b); |
1
|
530 } |
|
531 |
1567
|
532 retval = result; |
1
|
533 } |
|
534 else |
|
535 { |
|
536 Matrix result (nr, nc); |
|
537 for (int j = 0; j < nc; j++) |
|
538 for (int i = 0; i < nr; i++) |
2305
|
539 result (i, j) = pow (a (i, j), b); |
1
|
540 |
1567
|
541 retval = result; |
1
|
542 } |
|
543 |
|
544 return retval; |
|
545 } |
|
546 |
767
|
547 // -*- 4 -*- |
2086
|
548 octave_value |
164
|
549 elem_xpow (const Matrix& a, const Matrix& b) |
1
|
550 { |
2086
|
551 octave_value retval; |
1567
|
552 |
1
|
553 int nr = a.rows (); |
2365
|
554 int nc = a.cols (); |
|
555 |
|
556 int b_nr = b.rows (); |
|
557 int b_nc = b.cols (); |
1
|
558 |
2365
|
559 if (nr != b_nr || nc != b_nc) |
|
560 { |
|
561 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
|
562 return octave_value (); |
|
563 } |
1
|
564 |
|
565 int convert_to_complex = 0; |
|
566 for (int j = 0; j < nc; j++) |
1321
|
567 for (int i = 0; i < nr; i++) |
1
|
568 { |
2305
|
569 double atmp = a (i, j); |
|
570 double btmp = b (i, j); |
2800
|
571 if (atmp < 0.0 && static_cast<int> (btmp) != btmp) |
1
|
572 { |
|
573 convert_to_complex = 1; |
|
574 goto done; |
|
575 } |
|
576 } |
|
577 |
2365
|
578 done: |
1
|
579 |
|
580 if (convert_to_complex) |
|
581 { |
|
582 ComplexMatrix complex_result (nr, nc); |
|
583 |
1321
|
584 for (int j = 0; j < nc; j++) |
|
585 for (int i = 0; i < nr; i++) |
1
|
586 { |
2305
|
587 Complex atmp (a (i, j)); |
|
588 Complex btmp (b (i, j)); |
|
589 complex_result (i, j) = pow (atmp, btmp); |
1
|
590 } |
1567
|
591 |
|
592 retval = complex_result; |
1
|
593 } |
|
594 else |
|
595 { |
|
596 Matrix result (nr, nc); |
|
597 |
1321
|
598 for (int j = 0; j < nc; j++) |
|
599 for (int i = 0; i < nr; i++) |
2305
|
600 result (i, j) = pow (a (i, j), b (i, j)); |
1
|
601 |
1567
|
602 retval = result; |
1
|
603 } |
1567
|
604 |
|
605 return retval; |
1
|
606 } |
|
607 |
767
|
608 // -*- 5 -*- |
2086
|
609 octave_value |
164
|
610 elem_xpow (const Matrix& a, const Complex& b) |
1
|
611 { |
|
612 int nr = a.rows (); |
2365
|
613 int nc = a.cols (); |
1
|
614 |
|
615 ComplexMatrix result (nr, nc); |
|
616 for (int j = 0; j < nc; j++) |
|
617 for (int i = 0; i < nr; i++) |
3125
|
618 result (i, j) = pow (Complex (a (i, j)), b); |
1
|
619 |
1567
|
620 return result; |
1
|
621 } |
|
622 |
767
|
623 // -*- 6 -*- |
2086
|
624 octave_value |
164
|
625 elem_xpow (const Matrix& a, const ComplexMatrix& b) |
1
|
626 { |
|
627 int nr = a.rows (); |
2365
|
628 int nc = a.cols (); |
|
629 |
|
630 int b_nr = b.rows (); |
|
631 int b_nc = b.cols (); |
1
|
632 |
2365
|
633 if (nr != b_nr || nc != b_nc) |
|
634 { |
|
635 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
|
636 return octave_value (); |
|
637 } |
1
|
638 |
|
639 ComplexMatrix result (nr, nc); |
|
640 for (int j = 0; j < nc; j++) |
|
641 for (int i = 0; i < nr; i++) |
3125
|
642 result (i, j) = pow (Complex (a (i, j)), b (i, j)); |
1
|
643 |
1567
|
644 return result; |
1
|
645 } |
|
646 |
767
|
647 // -*- 7 -*- |
2086
|
648 octave_value |
164
|
649 elem_xpow (const Complex& a, const Matrix& b) |
1
|
650 { |
|
651 int nr = b.rows (); |
2365
|
652 int nc = b.cols (); |
1
|
653 |
|
654 ComplexMatrix result (nr, nc); |
|
655 for (int j = 0; j < nc; j++) |
|
656 for (int i = 0; i < nr; i++) |
1567
|
657 { |
2305
|
658 double btmp = b (i, j); |
1567
|
659 if (xisint (btmp)) |
2800
|
660 result (i, j) = pow (a, static_cast<int> (btmp)); |
1567
|
661 else |
2305
|
662 result (i, j) = pow (a, btmp); |
1567
|
663 } |
1
|
664 |
1567
|
665 return result; |
1
|
666 } |
|
667 |
767
|
668 // -*- 8 -*- |
2086
|
669 octave_value |
164
|
670 elem_xpow (const Complex& a, const ComplexMatrix& b) |
1
|
671 { |
|
672 int nr = b.rows (); |
2365
|
673 int nc = b.cols (); |
1
|
674 |
|
675 ComplexMatrix result (nr, nc); |
|
676 for (int j = 0; j < nc; j++) |
|
677 for (int i = 0; i < nr; i++) |
2305
|
678 result (i, j) = pow (a, b (i, j)); |
1
|
679 |
1567
|
680 return result; |
1
|
681 } |
|
682 |
767
|
683 // -*- 9 -*- |
2086
|
684 octave_value |
164
|
685 elem_xpow (const ComplexMatrix& a, double b) |
1
|
686 { |
|
687 int nr = a.rows (); |
2365
|
688 int nc = a.cols (); |
1
|
689 |
|
690 ComplexMatrix result (nr, nc); |
|
691 |
1567
|
692 if (xisint (b)) |
|
693 { |
|
694 for (int j = 0; j < nc; j++) |
|
695 for (int i = 0; i < nr; i++) |
2800
|
696 result (i, j) = pow (a (i, j), static_cast<int> (b)); |
1567
|
697 } |
|
698 else |
|
699 { |
|
700 for (int j = 0; j < nc; j++) |
|
701 for (int i = 0; i < nr; i++) |
2305
|
702 result (i, j) = pow (a (i, j), b); |
1567
|
703 } |
|
704 |
|
705 return result; |
1
|
706 } |
|
707 |
767
|
708 // -*- 10 -*- |
2086
|
709 octave_value |
164
|
710 elem_xpow (const ComplexMatrix& a, const Matrix& b) |
1
|
711 { |
|
712 int nr = a.rows (); |
2365
|
713 int nc = a.cols (); |
|
714 |
|
715 int b_nr = b.rows (); |
|
716 int b_nc = b.cols (); |
1
|
717 |
2365
|
718 if (nr != b_nr || nc != b_nc) |
|
719 { |
|
720 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
|
721 return octave_value (); |
|
722 } |
1
|
723 |
|
724 ComplexMatrix result (nr, nc); |
|
725 for (int j = 0; j < nc; j++) |
|
726 for (int i = 0; i < nr; i++) |
1567
|
727 { |
2305
|
728 double btmp = b (i, j); |
1567
|
729 if (xisint (btmp)) |
2800
|
730 result (i, j) = pow (a (i, j), static_cast<int> (btmp)); |
1567
|
731 else |
2305
|
732 result (i, j) = pow (a (i, j), btmp); |
1567
|
733 } |
1
|
734 |
1567
|
735 return result; |
1
|
736 } |
|
737 |
767
|
738 // -*- 11 -*- |
2086
|
739 octave_value |
164
|
740 elem_xpow (const ComplexMatrix& a, const Complex& b) |
1
|
741 { |
|
742 int nr = a.rows (); |
2365
|
743 int nc = a.cols (); |
1
|
744 |
|
745 ComplexMatrix result (nr, nc); |
|
746 for (int j = 0; j < nc; j++) |
|
747 for (int i = 0; i < nr; i++) |
2305
|
748 result (i, j) = pow (a (i, j), b); |
1
|
749 |
1567
|
750 return result; |
1
|
751 } |
|
752 |
767
|
753 // -*- 12 -*- |
2086
|
754 octave_value |
164
|
755 elem_xpow (const ComplexMatrix& a, const ComplexMatrix& b) |
1
|
756 { |
|
757 int nr = a.rows (); |
2365
|
758 int nc = a.cols (); |
|
759 |
|
760 int b_nr = b.rows (); |
|
761 int b_nc = b.cols (); |
|
762 |
|
763 if (nr != b_nr || nc != b_nc) |
|
764 { |
|
765 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
|
766 return octave_value (); |
|
767 } |
1
|
768 |
|
769 ComplexMatrix result (nr, nc); |
|
770 for (int j = 0; j < nc; j++) |
|
771 for (int i = 0; i < nr; i++) |
2305
|
772 result (i, j) = pow (a (i, j), b (i, j)); |
1
|
773 |
1567
|
774 return result; |
1
|
775 } |
|
776 |
|
777 /* |
|
778 ;;; Local Variables: *** |
|
779 ;;; mode: C++ *** |
|
780 ;;; End: *** |
|
781 */ |