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 |
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); |
3125
|
491 Complex atmp (a); |
1
|
492 for (int j = 0; j < nc; j++) |
|
493 for (int i = 0; i < nr; i++) |
3125
|
494 result (i, j) = pow (atmp, b (i, j)); |
1
|
495 |
1567
|
496 return result; |
1
|
497 } |
|
498 |
767
|
499 // -*- 3 -*- |
2086
|
500 octave_value |
164
|
501 elem_xpow (const Matrix& a, double b) |
1
|
502 { |
2086
|
503 octave_value retval; |
1
|
504 |
|
505 int nr = a.rows (); |
2365
|
506 int nc = a.cols (); |
1
|
507 |
2800
|
508 if (static_cast<int> (b) != b && a.any_element_is_negative ()) |
1
|
509 { |
|
510 ComplexMatrix result (nr, nc); |
|
511 for (int j = 0; j < nc; j++) |
|
512 for (int i = 0; i < nr; i++) |
|
513 { |
2305
|
514 Complex atmp (a (i, j)); |
|
515 result (i, j) = pow (atmp, b); |
1
|
516 } |
|
517 |
1567
|
518 retval = result; |
1
|
519 } |
|
520 else |
|
521 { |
|
522 Matrix result (nr, nc); |
|
523 for (int j = 0; j < nc; j++) |
|
524 for (int i = 0; i < nr; i++) |
2305
|
525 result (i, j) = pow (a (i, j), b); |
1
|
526 |
1567
|
527 retval = result; |
1
|
528 } |
|
529 |
|
530 return retval; |
|
531 } |
|
532 |
767
|
533 // -*- 4 -*- |
2086
|
534 octave_value |
164
|
535 elem_xpow (const Matrix& a, const Matrix& b) |
1
|
536 { |
2086
|
537 octave_value retval; |
1567
|
538 |
1
|
539 int nr = a.rows (); |
2365
|
540 int nc = a.cols (); |
|
541 |
|
542 int b_nr = b.rows (); |
|
543 int b_nc = b.cols (); |
1
|
544 |
2365
|
545 if (nr != b_nr || nc != b_nc) |
|
546 { |
|
547 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
|
548 return octave_value (); |
|
549 } |
1
|
550 |
|
551 int convert_to_complex = 0; |
|
552 for (int j = 0; j < nc; j++) |
1321
|
553 for (int i = 0; i < nr; i++) |
1
|
554 { |
2305
|
555 double atmp = a (i, j); |
|
556 double btmp = b (i, j); |
2800
|
557 if (atmp < 0.0 && static_cast<int> (btmp) != btmp) |
1
|
558 { |
|
559 convert_to_complex = 1; |
|
560 goto done; |
|
561 } |
|
562 } |
|
563 |
2365
|
564 done: |
1
|
565 |
|
566 if (convert_to_complex) |
|
567 { |
|
568 ComplexMatrix complex_result (nr, nc); |
|
569 |
1321
|
570 for (int j = 0; j < nc; j++) |
|
571 for (int i = 0; i < nr; i++) |
1
|
572 { |
2305
|
573 Complex atmp (a (i, j)); |
|
574 Complex btmp (b (i, j)); |
|
575 complex_result (i, j) = pow (atmp, btmp); |
1
|
576 } |
1567
|
577 |
|
578 retval = complex_result; |
1
|
579 } |
|
580 else |
|
581 { |
|
582 Matrix result (nr, nc); |
|
583 |
1321
|
584 for (int j = 0; j < nc; j++) |
|
585 for (int i = 0; i < nr; i++) |
2305
|
586 result (i, j) = pow (a (i, j), b (i, j)); |
1
|
587 |
1567
|
588 retval = result; |
1
|
589 } |
1567
|
590 |
|
591 return retval; |
1
|
592 } |
|
593 |
767
|
594 // -*- 5 -*- |
2086
|
595 octave_value |
164
|
596 elem_xpow (const Matrix& a, const Complex& b) |
1
|
597 { |
|
598 int nr = a.rows (); |
2365
|
599 int nc = a.cols (); |
1
|
600 |
|
601 ComplexMatrix result (nr, nc); |
|
602 for (int j = 0; j < nc; j++) |
|
603 for (int i = 0; i < nr; i++) |
3125
|
604 result (i, j) = pow (Complex (a (i, j)), b); |
1
|
605 |
1567
|
606 return result; |
1
|
607 } |
|
608 |
767
|
609 // -*- 6 -*- |
2086
|
610 octave_value |
164
|
611 elem_xpow (const Matrix& a, const ComplexMatrix& b) |
1
|
612 { |
|
613 int nr = a.rows (); |
2365
|
614 int nc = a.cols (); |
|
615 |
|
616 int b_nr = b.rows (); |
|
617 int b_nc = b.cols (); |
1
|
618 |
2365
|
619 if (nr != b_nr || nc != b_nc) |
|
620 { |
|
621 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
|
622 return octave_value (); |
|
623 } |
1
|
624 |
|
625 ComplexMatrix result (nr, nc); |
|
626 for (int j = 0; j < nc; j++) |
|
627 for (int i = 0; i < nr; i++) |
3125
|
628 result (i, j) = pow (Complex (a (i, j)), b (i, j)); |
1
|
629 |
1567
|
630 return result; |
1
|
631 } |
|
632 |
767
|
633 // -*- 7 -*- |
2086
|
634 octave_value |
164
|
635 elem_xpow (const Complex& a, const Matrix& b) |
1
|
636 { |
|
637 int nr = b.rows (); |
2365
|
638 int nc = b.cols (); |
1
|
639 |
|
640 ComplexMatrix result (nr, nc); |
|
641 for (int j = 0; j < nc; j++) |
|
642 for (int i = 0; i < nr; i++) |
1567
|
643 { |
2305
|
644 double btmp = b (i, j); |
1567
|
645 if (xisint (btmp)) |
2800
|
646 result (i, j) = pow (a, static_cast<int> (btmp)); |
1567
|
647 else |
2305
|
648 result (i, j) = pow (a, btmp); |
1567
|
649 } |
1
|
650 |
1567
|
651 return result; |
1
|
652 } |
|
653 |
767
|
654 // -*- 8 -*- |
2086
|
655 octave_value |
164
|
656 elem_xpow (const Complex& a, const ComplexMatrix& b) |
1
|
657 { |
|
658 int nr = b.rows (); |
2365
|
659 int nc = b.cols (); |
1
|
660 |
|
661 ComplexMatrix result (nr, nc); |
|
662 for (int j = 0; j < nc; j++) |
|
663 for (int i = 0; i < nr; i++) |
2305
|
664 result (i, j) = pow (a, b (i, j)); |
1
|
665 |
1567
|
666 return result; |
1
|
667 } |
|
668 |
767
|
669 // -*- 9 -*- |
2086
|
670 octave_value |
164
|
671 elem_xpow (const ComplexMatrix& a, double b) |
1
|
672 { |
|
673 int nr = a.rows (); |
2365
|
674 int nc = a.cols (); |
1
|
675 |
|
676 ComplexMatrix result (nr, nc); |
|
677 |
1567
|
678 if (xisint (b)) |
|
679 { |
|
680 for (int j = 0; j < nc; j++) |
|
681 for (int i = 0; i < nr; i++) |
2800
|
682 result (i, j) = pow (a (i, j), static_cast<int> (b)); |
1567
|
683 } |
|
684 else |
|
685 { |
|
686 for (int j = 0; j < nc; j++) |
|
687 for (int i = 0; i < nr; i++) |
2305
|
688 result (i, j) = pow (a (i, j), b); |
1567
|
689 } |
|
690 |
|
691 return result; |
1
|
692 } |
|
693 |
767
|
694 // -*- 10 -*- |
2086
|
695 octave_value |
164
|
696 elem_xpow (const ComplexMatrix& a, const Matrix& b) |
1
|
697 { |
|
698 int nr = a.rows (); |
2365
|
699 int nc = a.cols (); |
|
700 |
|
701 int b_nr = b.rows (); |
|
702 int b_nc = b.cols (); |
1
|
703 |
2365
|
704 if (nr != b_nr || nc != b_nc) |
|
705 { |
|
706 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
|
707 return octave_value (); |
|
708 } |
1
|
709 |
|
710 ComplexMatrix result (nr, nc); |
|
711 for (int j = 0; j < nc; j++) |
|
712 for (int i = 0; i < nr; i++) |
1567
|
713 { |
2305
|
714 double btmp = b (i, j); |
1567
|
715 if (xisint (btmp)) |
2800
|
716 result (i, j) = pow (a (i, j), static_cast<int> (btmp)); |
1567
|
717 else |
2305
|
718 result (i, j) = pow (a (i, j), btmp); |
1567
|
719 } |
1
|
720 |
1567
|
721 return result; |
1
|
722 } |
|
723 |
767
|
724 // -*- 11 -*- |
2086
|
725 octave_value |
164
|
726 elem_xpow (const ComplexMatrix& a, const Complex& b) |
1
|
727 { |
|
728 int nr = a.rows (); |
2365
|
729 int nc = a.cols (); |
1
|
730 |
|
731 ComplexMatrix result (nr, nc); |
|
732 for (int j = 0; j < nc; j++) |
|
733 for (int i = 0; i < nr; i++) |
2305
|
734 result (i, j) = pow (a (i, j), b); |
1
|
735 |
1567
|
736 return result; |
1
|
737 } |
|
738 |
767
|
739 // -*- 12 -*- |
2086
|
740 octave_value |
164
|
741 elem_xpow (const ComplexMatrix& a, const ComplexMatrix& b) |
1
|
742 { |
|
743 int nr = a.rows (); |
2365
|
744 int nc = a.cols (); |
|
745 |
|
746 int b_nr = b.rows (); |
|
747 int b_nc = b.cols (); |
|
748 |
|
749 if (nr != b_nr || nc != b_nc) |
|
750 { |
|
751 gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
|
752 return octave_value (); |
|
753 } |
1
|
754 |
|
755 ComplexMatrix result (nr, nc); |
|
756 for (int j = 0; j < nc; j++) |
|
757 for (int i = 0; i < nr; i++) |
2305
|
758 result (i, j) = pow (a (i, j), b (i, j)); |
1
|
759 |
1567
|
760 return result; |
1
|
761 } |
|
762 |
|
763 /* |
|
764 ;;; Local Variables: *** |
|
765 ;;; mode: C++ *** |
|
766 ;;; End: *** |
|
767 */ |