1993
|
1 // RowVector manipulations. |
458
|
2 /* |
|
3 |
1882
|
4 Copyright (C) 1996 John W. Eaton |
458
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
458
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
458
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
458
|
30 #endif |
|
31 |
|
32 #include <iostream.h> |
|
33 |
1847
|
34 #include "f77-fcn.h" |
1368
|
35 #include "lo-error.h" |
458
|
36 #include "mx-base.h" |
|
37 #include "mx-inlines.cc" |
1650
|
38 #include "oct-cmplx.h" |
458
|
39 |
|
40 // Fortran functions we call. |
|
41 |
|
42 extern "C" |
|
43 { |
1253
|
44 int F77_FCN (zgemv, ZGEMV) (const char*, const int&, const int&, |
|
45 const Complex&, const Complex*, |
|
46 const int&, const Complex*, const int&, |
|
47 const Complex&, Complex*, const int&, |
|
48 long); |
458
|
49 } |
|
50 |
1360
|
51 // Complex Row Vector class |
458
|
52 |
|
53 ComplexRowVector::ComplexRowVector (const RowVector& a) |
1214
|
54 : MArray<Complex> (a.length ()) |
458
|
55 { |
|
56 for (int i = 0; i < length (); i++) |
|
57 elem (i) = a.elem (i); |
|
58 } |
|
59 |
|
60 int |
|
61 ComplexRowVector::operator == (const ComplexRowVector& a) const |
|
62 { |
|
63 int len = length (); |
|
64 if (len != a.length ()) |
|
65 return 0; |
|
66 return equal (data (), a.data (), len); |
|
67 } |
|
68 |
|
69 int |
|
70 ComplexRowVector::operator != (const ComplexRowVector& a) const |
|
71 { |
|
72 return !(*this == a); |
|
73 } |
|
74 |
|
75 // destructive insert/delete/reorder operations |
|
76 |
|
77 ComplexRowVector& |
|
78 ComplexRowVector::insert (const RowVector& a, int c) |
|
79 { |
|
80 int a_len = a.length (); |
1699
|
81 if (c < 0 || c + a_len > length ()) |
458
|
82 { |
|
83 (*current_liboctave_error_handler) ("range error for insert"); |
|
84 return *this; |
|
85 } |
|
86 |
|
87 for (int i = 0; i < a_len; i++) |
|
88 elem (c+i) = a.elem (i); |
|
89 |
|
90 return *this; |
|
91 } |
|
92 |
|
93 ComplexRowVector& |
|
94 ComplexRowVector::insert (const ComplexRowVector& a, int c) |
|
95 { |
|
96 int a_len = a.length (); |
1699
|
97 if (c < 0 || c + a_len > length ()) |
458
|
98 { |
|
99 (*current_liboctave_error_handler) ("range error for insert"); |
|
100 return *this; |
|
101 } |
|
102 |
|
103 for (int i = 0; i < a_len; i++) |
|
104 elem (c+i) = a.elem (i); |
|
105 |
|
106 return *this; |
|
107 } |
|
108 |
|
109 ComplexRowVector& |
|
110 ComplexRowVector::fill (double val) |
|
111 { |
|
112 int len = length (); |
|
113 if (len > 0) |
|
114 for (int i = 0; i < len; i++) |
|
115 elem (i) = val; |
|
116 return *this; |
|
117 } |
|
118 |
|
119 ComplexRowVector& |
|
120 ComplexRowVector::fill (const Complex& val) |
|
121 { |
|
122 int len = length (); |
|
123 if (len > 0) |
|
124 for (int i = 0; i < len; i++) |
|
125 elem (i) = val; |
|
126 return *this; |
|
127 } |
|
128 |
|
129 ComplexRowVector& |
|
130 ComplexRowVector::fill (double val, int c1, int c2) |
|
131 { |
|
132 int len = length (); |
|
133 if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) |
|
134 { |
|
135 (*current_liboctave_error_handler) ("range error for fill"); |
|
136 return *this; |
|
137 } |
|
138 |
|
139 if (c1 > c2) { int tmp = c1; c1 = c2; c2 = tmp; } |
|
140 |
|
141 for (int i = c1; i <= c2; i++) |
|
142 elem (i) = val; |
|
143 |
|
144 return *this; |
|
145 } |
|
146 |
|
147 ComplexRowVector& |
|
148 ComplexRowVector::fill (const Complex& val, int c1, int c2) |
|
149 { |
|
150 int len = length (); |
|
151 if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) |
|
152 { |
|
153 (*current_liboctave_error_handler) ("range error for fill"); |
|
154 return *this; |
|
155 } |
|
156 |
|
157 if (c1 > c2) { int tmp = c1; c1 = c2; c2 = tmp; } |
|
158 |
|
159 for (int i = c1; i <= c2; i++) |
|
160 elem (i) = val; |
|
161 |
|
162 return *this; |
|
163 } |
|
164 |
|
165 ComplexRowVector |
|
166 ComplexRowVector::append (const RowVector& a) const |
|
167 { |
|
168 int len = length (); |
|
169 int nc_insert = len; |
|
170 ComplexRowVector retval (len + a.length ()); |
|
171 retval.insert (*this, 0); |
|
172 retval.insert (a, nc_insert); |
|
173 return retval; |
|
174 } |
|
175 |
|
176 ComplexRowVector |
|
177 ComplexRowVector::append (const ComplexRowVector& a) const |
|
178 { |
|
179 int len = length (); |
|
180 int nc_insert = len; |
|
181 ComplexRowVector retval (len + a.length ()); |
|
182 retval.insert (*this, 0); |
|
183 retval.insert (a, nc_insert); |
|
184 return retval; |
|
185 } |
|
186 |
|
187 ComplexColumnVector |
|
188 ComplexRowVector::hermitian (void) const |
|
189 { |
|
190 int len = length (); |
|
191 return ComplexColumnVector (conj_dup (data (), len), len); |
|
192 } |
|
193 |
|
194 ComplexColumnVector |
|
195 ComplexRowVector::transpose (void) const |
|
196 { |
1858
|
197 return ComplexColumnVector (*this); |
458
|
198 } |
|
199 |
|
200 ComplexRowVector |
|
201 conj (const ComplexRowVector& a) |
|
202 { |
|
203 int a_len = a.length (); |
|
204 ComplexRowVector retval; |
|
205 if (a_len > 0) |
|
206 retval = ComplexRowVector (conj_dup (a.data (), a_len), a_len); |
|
207 return retval; |
|
208 } |
|
209 |
|
210 // resize is the destructive equivalent for this one |
|
211 |
|
212 ComplexRowVector |
|
213 ComplexRowVector::extract (int c1, int c2) const |
|
214 { |
|
215 if (c1 > c2) { int tmp = c1; c1 = c2; c2 = tmp; } |
|
216 |
|
217 int new_c = c2 - c1 + 1; |
|
218 |
|
219 ComplexRowVector result (new_c); |
|
220 |
|
221 for (int i = 0; i < new_c; i++) |
|
222 result.elem (i) = elem (c1+i); |
|
223 |
|
224 return result; |
|
225 } |
|
226 |
|
227 // row vector by row vector -> row vector operations |
|
228 |
|
229 ComplexRowVector& |
|
230 ComplexRowVector::operator += (const RowVector& a) |
|
231 { |
|
232 int len = length (); |
|
233 if (len != a.length ()) |
|
234 { |
|
235 (*current_liboctave_error_handler) |
|
236 ("nonconformant vector += operation attempted"); |
|
237 return *this; |
|
238 } |
|
239 |
|
240 if (len == 0) |
|
241 return *this; |
|
242 |
|
243 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
244 |
|
245 add2 (d, a.data (), len); |
|
246 return *this; |
|
247 } |
|
248 |
|
249 ComplexRowVector& |
|
250 ComplexRowVector::operator -= (const RowVector& a) |
|
251 { |
|
252 int len = length (); |
|
253 if (len != a.length ()) |
|
254 { |
|
255 (*current_liboctave_error_handler) |
|
256 ("nonconformant vector -= operation attempted"); |
|
257 return *this; |
|
258 } |
|
259 |
|
260 if (len == 0) |
|
261 return *this; |
|
262 |
|
263 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
264 |
|
265 subtract2 (d, a.data (), len); |
|
266 return *this; |
|
267 } |
|
268 |
|
269 ComplexRowVector& |
|
270 ComplexRowVector::operator += (const ComplexRowVector& a) |
|
271 { |
|
272 int len = length (); |
|
273 if (len != a.length ()) |
|
274 { |
|
275 (*current_liboctave_error_handler) |
|
276 ("nonconformant vector += operation attempted"); |
|
277 return *this; |
|
278 } |
|
279 |
|
280 if (len == 0) |
|
281 return *this; |
|
282 |
|
283 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
284 |
|
285 add2 (d, a.data (), len); |
|
286 return *this; |
|
287 } |
|
288 |
|
289 ComplexRowVector& |
|
290 ComplexRowVector::operator -= (const ComplexRowVector& a) |
|
291 { |
|
292 int len = length (); |
|
293 if (len != a.length ()) |
|
294 { |
|
295 (*current_liboctave_error_handler) |
|
296 ("nonconformant vector -= operation attempted"); |
|
297 return *this; |
|
298 } |
|
299 |
|
300 if (len == 0) |
|
301 return *this; |
|
302 |
|
303 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
304 |
|
305 subtract2 (d, a.data (), len); |
|
306 return *this; |
|
307 } |
|
308 |
|
309 // row vector by scalar -> row vector operations |
|
310 |
|
311 ComplexRowVector |
|
312 operator + (const ComplexRowVector& v, double s) |
|
313 { |
|
314 int len = v.length (); |
|
315 return ComplexRowVector (add (v.data (), len, s), len); |
|
316 } |
|
317 |
|
318 ComplexRowVector |
|
319 operator - (const ComplexRowVector& v, double s) |
|
320 { |
|
321 int len = v.length (); |
|
322 return ComplexRowVector (subtract (v.data (), len, s), len); |
|
323 } |
|
324 |
|
325 ComplexRowVector |
|
326 operator * (const ComplexRowVector& v, double s) |
|
327 { |
|
328 int len = v.length (); |
|
329 return ComplexRowVector (multiply (v.data (), len, s), len); |
|
330 } |
|
331 |
|
332 ComplexRowVector |
|
333 operator / (const ComplexRowVector& v, double s) |
|
334 { |
|
335 int len = v.length (); |
|
336 return ComplexRowVector (divide (v.data (), len, s), len); |
|
337 } |
|
338 |
1205
|
339 ComplexRowVector |
|
340 operator + (const RowVector& v, const Complex& s) |
|
341 { |
|
342 int len = v.length (); |
|
343 return ComplexRowVector (add (v.data (), len, s), len); |
|
344 } |
|
345 |
|
346 ComplexRowVector |
|
347 operator - (const RowVector& v, const Complex& s) |
|
348 { |
|
349 int len = v.length (); |
|
350 return ComplexRowVector (subtract (v.data (), len, s), len); |
|
351 } |
|
352 |
|
353 ComplexRowVector |
|
354 operator * (const RowVector& v, const Complex& s) |
|
355 { |
|
356 int len = v.length (); |
|
357 return ComplexRowVector (multiply (v.data (), len, s), len); |
|
358 } |
|
359 |
|
360 ComplexRowVector |
|
361 operator / (const RowVector& v, const Complex& s) |
|
362 { |
|
363 int len = v.length (); |
|
364 return ComplexRowVector (divide (v.data (), len, s), len); |
|
365 } |
|
366 |
458
|
367 // scalar by row vector -> row vector operations |
|
368 |
|
369 ComplexRowVector |
|
370 operator + (double s, const ComplexRowVector& a) |
|
371 { |
|
372 int a_len = a.length (); |
|
373 return ComplexRowVector (add (a.data (), a_len, s), a_len); |
|
374 } |
|
375 |
|
376 ComplexRowVector |
|
377 operator - (double s, const ComplexRowVector& a) |
|
378 { |
|
379 int a_len = a.length (); |
|
380 return ComplexRowVector (subtract (s, a.data (), a_len), a_len); |
|
381 } |
|
382 |
|
383 ComplexRowVector |
|
384 operator * (double s, const ComplexRowVector& a) |
|
385 { |
|
386 int a_len = a.length (); |
|
387 return ComplexRowVector (multiply (a.data (), a_len, s), a_len); |
|
388 } |
|
389 |
|
390 ComplexRowVector |
|
391 operator / (double s, const ComplexRowVector& a) |
|
392 { |
|
393 int a_len = a.length (); |
|
394 return ComplexRowVector (divide (s, a.data (), a_len), a_len); |
|
395 } |
|
396 |
1205
|
397 ComplexRowVector |
|
398 operator + (const Complex& s, const RowVector& a) |
458
|
399 { |
1485
|
400 int a_len = a.length (); |
|
401 return ComplexRowVector (add (a.data (), a_len, s), a_len); |
458
|
402 } |
|
403 |
1205
|
404 ComplexRowVector |
|
405 operator - (const Complex& s, const RowVector& a) |
458
|
406 { |
1485
|
407 int a_len = a.length (); |
|
408 return ComplexRowVector (subtract (s, a.data (), a_len), a_len); |
1205
|
409 } |
458
|
410 |
1205
|
411 ComplexRowVector |
|
412 operator * (const Complex& s, const RowVector& a) |
|
413 { |
1485
|
414 int a_len = a.length (); |
|
415 return ComplexRowVector (multiply (a.data (), a_len, s), a_len); |
1205
|
416 } |
458
|
417 |
1205
|
418 ComplexRowVector |
|
419 operator / (const Complex& s, const RowVector& a) |
|
420 { |
1485
|
421 int a_len = a.length (); |
|
422 return ComplexRowVector (divide (s, a.data (), a_len), a_len); |
458
|
423 } |
|
424 |
|
425 // row vector by matrix -> row vector |
|
426 |
|
427 ComplexRowVector |
|
428 operator * (const ComplexRowVector& v, const ComplexMatrix& a) |
|
429 { |
1947
|
430 ComplexRowVector retval; |
|
431 |
458
|
432 int len = v.length (); |
1947
|
433 |
458
|
434 if (a.rows () != len) |
1947
|
435 (*current_liboctave_error_handler) |
|
436 ("nonconformant vector multiplication attempted"); |
|
437 else |
458
|
438 { |
1947
|
439 int a_nr = a.rows (); |
|
440 int a_nc = a.cols (); |
|
441 |
|
442 if (len == 0) |
|
443 retval.resize (a_nc, 0.0); |
|
444 else |
|
445 { |
|
446 // Transpose A to form A'*x == (x'*A)' |
|
447 |
|
448 int ld = a_nr; |
|
449 |
|
450 retval.resize (a_nc); |
|
451 Complex *y = retval.fortran_vec (); |
|
452 |
|
453 F77_XFCN (zgemv, ZGEMV, ("T", a_nr, a_nc, 1.0, a.data (), |
|
454 ld, v.data (), 1, 0.0, y, 1, 1L)); |
|
455 |
|
456 if (f77_exception_encountered) |
|
457 (*current_liboctave_error_handler) |
|
458 ("unrecoverable error in zgemv"); |
|
459 } |
458
|
460 } |
|
461 |
1947
|
462 return retval; |
458
|
463 } |
|
464 |
1205
|
465 ComplexRowVector |
|
466 operator * (const RowVector& v, const ComplexMatrix& a) |
|
467 { |
|
468 ComplexRowVector tmp (v); |
|
469 return tmp * a; |
|
470 } |
|
471 |
458
|
472 // row vector by row vector -> row vector operations |
|
473 |
|
474 ComplexRowVector |
|
475 operator + (const ComplexRowVector& v, const RowVector& a) |
|
476 { |
|
477 int len = v.length (); |
|
478 if (len != a.length ()) |
|
479 { |
|
480 (*current_liboctave_error_handler) |
|
481 ("nonconformant vector addition attempted"); |
|
482 return ComplexRowVector (); |
|
483 } |
|
484 |
|
485 if (len == 0) |
|
486 return ComplexRowVector (0); |
|
487 |
|
488 return ComplexRowVector (add (v.data (), a.data (), len), len); |
|
489 } |
|
490 |
|
491 ComplexRowVector |
|
492 operator - (const ComplexRowVector& v, const RowVector& a) |
|
493 { |
|
494 int len = v.length (); |
|
495 if (len != a.length ()) |
|
496 { |
|
497 (*current_liboctave_error_handler) |
|
498 ("nonconformant vector subtraction attempted"); |
|
499 return ComplexRowVector (); |
|
500 } |
|
501 |
|
502 if (len == 0) |
|
503 return ComplexRowVector (0); |
|
504 |
|
505 return ComplexRowVector (subtract (v.data (), a.data (), len), len); |
|
506 } |
|
507 |
|
508 ComplexRowVector |
1205
|
509 operator + (const RowVector& v, const ComplexRowVector& a) |
|
510 { |
|
511 int len = v.length (); |
|
512 if (len != a.length ()) |
|
513 { |
|
514 (*current_liboctave_error_handler) |
|
515 ("nonconformant vector addition attempted"); |
|
516 return ComplexRowVector (); |
|
517 } |
|
518 |
|
519 if (len == 0) |
|
520 return ComplexRowVector (0); |
|
521 |
|
522 return ComplexRowVector (add (v.data (), a.data (), len), len); |
|
523 } |
|
524 |
|
525 ComplexRowVector |
|
526 operator - (const RowVector& v, const ComplexRowVector& a) |
|
527 { |
|
528 int len = v.length (); |
|
529 if (len != a.length ()) |
|
530 { |
|
531 (*current_liboctave_error_handler) |
|
532 ("nonconformant vector subtraction attempted"); |
|
533 return ComplexRowVector (); |
|
534 } |
|
535 |
|
536 if (len == 0) |
|
537 return ComplexRowVector (0); |
|
538 |
|
539 return ComplexRowVector (subtract (v.data (), a.data (), len), len); |
|
540 } |
|
541 |
|
542 ComplexRowVector |
458
|
543 product (const ComplexRowVector& v, const RowVector& a) |
|
544 { |
|
545 int len = v.length (); |
|
546 if (len != a.length ()) |
|
547 { |
|
548 (*current_liboctave_error_handler) |
|
549 ("nonconformant vector product attempted"); |
|
550 return ComplexRowVector (); |
|
551 } |
|
552 |
|
553 if (len == 0) |
|
554 return ComplexRowVector (0); |
|
555 |
|
556 return ComplexRowVector (multiply (v.data (), a.data (), len), len); |
|
557 } |
|
558 |
|
559 ComplexRowVector |
|
560 quotient (const ComplexRowVector& v, const RowVector& a) |
|
561 { |
|
562 int len = v.length (); |
|
563 if (len != a.length ()) |
|
564 { |
|
565 (*current_liboctave_error_handler) |
|
566 ("nonconformant vector quotient attempted"); |
|
567 return ComplexRowVector (); |
|
568 } |
|
569 |
|
570 if (len == 0) |
|
571 return ComplexRowVector (0); |
|
572 |
|
573 return ComplexRowVector (divide (v.data (), a.data (), len), len); |
|
574 } |
|
575 |
1205
|
576 ComplexRowVector |
|
577 product (const RowVector& v, const ComplexRowVector& a) |
|
578 { |
|
579 int len = v.length (); |
|
580 if (len != a.length ()) |
|
581 { |
|
582 (*current_liboctave_error_handler) |
|
583 ("nonconformant vector product attempted"); |
|
584 return ComplexRowVector (); |
|
585 } |
|
586 |
|
587 if (len == 0) |
|
588 return ComplexRowVector (0); |
|
589 |
|
590 return ComplexRowVector (multiply (v.data (), a.data (), len), len); |
|
591 } |
|
592 |
|
593 ComplexRowVector |
|
594 quotient (const RowVector& v, const ComplexRowVector& a) |
|
595 { |
|
596 int len = v.length (); |
|
597 if (len != a.length ()) |
|
598 { |
|
599 (*current_liboctave_error_handler) |
|
600 ("nonconformant vector quotient attempted"); |
|
601 return ComplexRowVector (); |
|
602 } |
|
603 |
|
604 if (len == 0) |
|
605 return ComplexRowVector (0); |
|
606 |
|
607 return ComplexRowVector (divide (v.data (), a.data (), len), len); |
|
608 } |
|
609 |
458
|
610 // other operations |
|
611 |
|
612 ComplexRowVector |
|
613 map (c_c_Mapper f, const ComplexRowVector& a) |
|
614 { |
|
615 ComplexRowVector b (a); |
|
616 b.map (f); |
|
617 return b; |
|
618 } |
|
619 |
|
620 void |
|
621 ComplexRowVector::map (c_c_Mapper f) |
|
622 { |
|
623 for (int i = 0; i < length (); i++) |
|
624 elem (i) = f (elem (i)); |
|
625 } |
|
626 |
|
627 Complex |
|
628 ComplexRowVector::min (void) const |
|
629 { |
|
630 int len = length (); |
|
631 if (len == 0) |
|
632 return Complex (0.0); |
|
633 |
|
634 Complex res = elem (0); |
|
635 double absres = abs (res); |
|
636 |
|
637 for (int i = 1; i < len; i++) |
|
638 if (abs (elem (i)) < absres) |
|
639 { |
|
640 res = elem (i); |
|
641 absres = abs (res); |
|
642 } |
|
643 |
|
644 return res; |
|
645 } |
|
646 |
|
647 Complex |
|
648 ComplexRowVector::max (void) const |
|
649 { |
|
650 int len = length (); |
|
651 if (len == 0) |
|
652 return Complex (0.0); |
|
653 |
|
654 Complex res = elem (0); |
|
655 double absres = abs (res); |
|
656 |
|
657 for (int i = 1; i < len; i++) |
|
658 if (abs (elem (i)) > absres) |
|
659 { |
|
660 res = elem (i); |
|
661 absres = abs (res); |
|
662 } |
|
663 |
|
664 return res; |
|
665 } |
|
666 |
|
667 // i/o |
|
668 |
|
669 ostream& |
|
670 operator << (ostream& os, const ComplexRowVector& a) |
|
671 { |
|
672 // int field_width = os.precision () + 7; |
|
673 for (int i = 0; i < a.length (); i++) |
|
674 os << " " /* setw (field_width) */ << a.elem (i); |
|
675 return os; |
|
676 } |
|
677 |
|
678 istream& |
|
679 operator >> (istream& is, ComplexRowVector& a) |
|
680 { |
|
681 int len = a.length(); |
|
682 |
|
683 if (len < 1) |
|
684 is.clear (ios::badbit); |
|
685 else |
|
686 { |
|
687 Complex tmp; |
|
688 for (int i = 0; i < len; i++) |
|
689 { |
|
690 is >> tmp; |
|
691 if (is) |
|
692 a.elem (i) = tmp; |
|
693 else |
|
694 break; |
|
695 } |
|
696 } |
532
|
697 return is; |
458
|
698 } |
|
699 |
1205
|
700 // row vector by column vector -> scalar |
|
701 |
|
702 // row vector by column vector -> scalar |
|
703 |
|
704 Complex |
|
705 operator * (const ComplexRowVector& v, const ColumnVector& a) |
|
706 { |
|
707 ComplexColumnVector tmp (a); |
|
708 return v * tmp; |
|
709 } |
|
710 |
|
711 Complex |
|
712 operator * (const ComplexRowVector& v, const ComplexColumnVector& a) |
|
713 { |
|
714 int len = v.length (); |
|
715 if (len != a.length ()) |
|
716 { |
|
717 (*current_liboctave_error_handler) |
|
718 ("nonconformant vector multiplication attempted"); |
|
719 return 0.0; |
|
720 } |
|
721 |
|
722 Complex retval (0.0, 0.0); |
|
723 |
|
724 for (int i = 0; i < len; i++) |
|
725 retval += v.elem (i) * a.elem (i); |
|
726 |
|
727 return retval; |
|
728 } |
|
729 |
|
730 // other operations |
|
731 |
|
732 ComplexRowVector |
|
733 linspace (const Complex& x1, const Complex& x2, int n) |
|
734 { |
|
735 ComplexRowVector retval; |
|
736 |
|
737 if (n > 0) |
|
738 { |
|
739 retval.resize (n); |
|
740 Complex delta = (x2 - x1) / (n - 1); |
|
741 retval.elem (0) = x1; |
|
742 for (int i = 1; i < n-1; i++) |
|
743 retval.elem (i) = x1 + i * delta; |
|
744 retval.elem (n-1) = x2; |
|
745 } |
|
746 |
|
747 return retval; |
|
748 } |
|
749 |
458
|
750 /* |
|
751 ;;; Local Variables: *** |
|
752 ;;; mode: C++ *** |
|
753 ;;; End: *** |
|
754 */ |